This project is archived and is in readonly mode.
create = False
Reported by Psycopg website | October 25th, 2011 @ 12:18 PM
Submitted by: yurj@alfa.it
def getconn(self, create=True):
conn = pool.getconn(self.dsn)
conn.set_isolation_level(int(self.tilevel))
conn.set_client_encoding(self.encoding)
for tc in self.typecasts:
register_type(tc, conn)
return conn
where's the test if create = False. With this code it is impossible to roll back with Zope.
Comments and changes to this ticket
-
yuri October 25th, 2011 @ 12:26 PM
def getconn(self, create=True):
conn = pool.getconn(self.dsn) if create == False: return conn conn.set_isolation_level(int(self.tilevel)) conn.set_client_encoding(self.encoding) for tc in self.typecasts: register_type(tc, conn) return conn
solve the problem.
Or am I totally wrong? :)
-
Federico Di Gregorio October 25th, 2011 @ 12:30 PM
"create" isn't used at all in that method. What do you mean by "impossible to roll back with Zope". Can you make an example?
-
yuri October 25th, 2011 @ 01:19 PM
install a fresh zope
create an adapter instance
go in "test"
write a wrong queryThen, you cannot submit other queries bacause of "current transaction is aborted, commands ignored until end of transaction block" feature.
I've to restart postgres or zope to submit (only correct) queries.
adding:
if create == False: return conn
solve the problem. This is because _abort requires the connection and call getconn with create=False. But there's no check in it, so conn.set_isolation_level(int(self.tilevel)) gives an exception because no rollback has been yet submitted.
-
Daniele Varrazzo November 3rd, 2011 @ 03:15 PM
yuri,
could you test the behaviour with the current head version (e.g. you may check it out from the devel branch in https://github.com/dvarrazzo/psycopg/).
The problem seems created by a bad connection in the pool. I've added a check to rollback connections in transaction and discard broken ones when returned to the pool, so the issue may have already been fixed.
Thank you.
-
yuri November 3rd, 2011 @ 03:47 PM
Thank you for the fix. I cannot see it, I mean I can understand what has changes. Also github seems to be at 2.4.1 version, and not 2.4.2... I'm not very good with github, can you explain me how I can see the change and how to download the correct version? :)
-
yuri November 3rd, 2011 @ 03:48 PM
"I cannot see it, I mean I can understand what has changes"
I can't understand, sorry for the mistake.
-
Daniele Varrazzo November 3rd, 2011 @ 03:56 PM
No problem:
git clone git://github.com/dvarrazzo/psycopg.git cd psycopg git co devel (it may say you are already on branch devel) make
you should have now a compiled version of psycopg in build/lib.2.6 (or whatever you python version is).
Cheers!
-
Daniele Varrazzo November 3rd, 2011 @ 03:56 PM
Sorry: "git co" should be "git checkout". "co" is an alias of mine.
-
yuri November 4th, 2011 @ 07:22 AM
Hi!
I've installed it, replaced the path in easyinstall.pth (I don't know if it is important but I did it), modified DA-py to get 2.4.3.dev0 version.
But the error is always the same, I can't see any change. Can you show me the change? I think the fix above is needed, it has not sense to create a new connection when you abort a transaction. But I'm not aware of how it works so I shut up :)
-
yuri November 4th, 2011 @ 07:25 AM
make just compiled it, I've run python setup.py build and then install, using the zope python. All seems correct to me.
-
Daniele Varrazzo November 4th, 2011 @ 09:09 AM
But the error is always the same, I can't see any change. Can you show me the change?
The change is this: https://github.com/dvarrazzo/psycopg/commit/a2ee25ecfe600a3d0c5d1ea...
I think the fix above is needed, it has not sense to create a new connection when you abort a transaction.
This is not what the patch does. The patch rolls back the connection if it is in transaction/in error, and discards it if broken.
make just compiled it, I've run python setup.py build and then install, using the zope python.
Yeah, could do.
Sorry, I can't help you further: I don't do Zope.
-
yuri November 4th, 2011 @ 09:29 AM
The problem is in the ZPsycopgDA adapter. Who is responsible of that code?
I think the fix above is needed, it has not sense to create a new connection when you abort a transaction. This is not what the patch does. The patch rolls back the connection if it is in transaction/in error, and discards it if broken.
Yes, but the ZPsycopgDA adapter does this:
def _abort(self, *ignored): try: conn = self.getconn(False) <-- here It calls getconn conn.rollback() self.putconn() except AttributeError: pass
and getconn(False):
def getconn(self, create=True): conn = pool.getconn(self.dsn) conn.set_isolation_level(int(self.tilevel)) <---- here the problem
set_isolation_level writes on the connection BEFORE the roolback done in conn.rollback().
getconn() should honour the False case, just returning the connection and not calling set_isolation_level because it writes on an unrolled postgres error and this gives and error and the rollback/abort is not performed.
I propose just to add the if create == False check:
def getconn(self, create=True):
conn = pool.getconn(self.dsn) if create == False: return conn ...
in the ZPsycopgDA/db.py code.
-
Federico Di Gregorio November 4th, 2011 @ 09:37 AM
Yuri, you're right and your patch is OK. I'll include it for 2.4.3.
-
Daniele Varrazzo December 19th, 2011 @ 12:53 PM
- State changed from new to resolved
Fix released in 2.4.4
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.