[FIX] sql_db: remove unused __closer

The `__closer` attribute is filled with the origin of a call to
`cr.close()`. That information is reused in the `check` decotator that
ensure the user is not using a closed cursor. In case he is using a
closed cursor, an error is raised with that optional origin in case of
`--log-sql`.

The attribute is a dundler so it is only accessible within its class, as
the decorator has been moved outside of the class by 058cf208a8 it is
not directly accessible thus `__getattr__` is called as a fallback. The
`__getattr__` itself is protected by the `check` decorator thus they
call each other in a infinite recursion.

As the related dundler is no more used internally, it has been decided
to remove it entirely.

closes odoo/odoo#47616

Task: 2199895
X-original-commit: 3ebf7cb9cca37b05f44aaffc0b1f289cc65f300f
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
This commit is contained in:
Julien Castiaux
2020-03-13 15:24:54 +00:00
parent a61ddfe87b
commit 92b17aadd2
+1 -8
View File
@@ -86,10 +86,7 @@ sql_counter = 0
def check(f, self, *args, **kwargs):
""" Wrap a cursor method that cannot be called when the cursor is closed. """
if self._closed:
msg = 'Unable to use a closed cursor.'
if self.__closer:
msg += ' It was closed at %s, line %s' % self.__closer
raise psycopg2.OperationalError(msg)
raise psycopg2.OperationalError('Unable to use a closed cursor.')
return f(self, *args, **kwargs)
@@ -248,7 +245,6 @@ class Cursor(BaseCursor):
self.__caller = False
self._closed = False # real initialisation value
self.autocommit(False)
self.__closer = False
self._default_log_exceptions = True
@@ -362,9 +358,6 @@ class Cursor(BaseCursor):
del self.cache
if self.sql_log:
self.__closer = frame_codeinfo(currentframe(), 3)
# simple query count is always computed
sql_counter += self.sql_log_count