[postmodern-devel] Postgres transaction warnings and save-dao
Peter Stiernström
peter.stiernstrom at blixtvik.se
Tue Mar 9 09:20:15 UTC 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I'm using postmodern with great success but I keep seeing these two
warnings in my log:
- "Postgres warning: there is no transaction in progress"
- "Warning while processing connection: Postgres warning: there is
already a transaction in progress"
As far as I can tell these are merely warnings but they're filling up my
logs so I had a look at what was causing it and I found that save-dao
has a (with-transaction () ...) wrapping an insert-dao and I was calling
save-dao from within my own transaction block.
Now if just remove the with-transaction from save-dao an duplicate key
violation will ruin the outer transaction by just aborting it
(regardless of the error handling code. However if I add a savepoint
just before trying insert-dao and in the error handling code use
rollback-savepoint to restore to this savepoint I can make the warnings
go away.
The problem now being that save-dao expects to be called within a
with-transaction form. So I was wondering if there is some way to tell
if we are within a transaction (e.g. within-transaction-p)? Then I would
be able to make a modification that handles both cases.
It might then look something like this:
(defun save-dao (dao)
(if (within-transaction-p)
(with-savepoint save-dao
(handler-case (progn (insert-dao dao) t)
(cl-postgres-error:unique-violation ()
(rollback-savepoint save-dao)
(update-dao dao)
nil))))
(handler-case (with-transaction () (insert-dao dao) t)
(cl-postgres-error:unique-violation ()
(update-dao dao)
nil)))
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkuWEs8ACgkQ0brSZD05ZzAj7wCfbhPynKyGMStzsRP/3MIGpOSH
6IcAni232P2lQ8/hAh5+03NmFr0FSbMs
=EIRi
-----END PGP SIGNATURE-----
More information about the postmodern-devel
mailing list