Skip to content

Conversation

@jeriox
Copy link
Contributor

@jeriox jeriox commented Oct 22, 2023

closes #949

@coveralls
Copy link

coveralls commented Oct 22, 2023

Coverage Status

coverage: 84.399% (+0.005%) from 84.394%
when pulling f3a885e on psycopg3
into 11434ec on main.

Copy link
Member

@felixrindt felixrindt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixrindt felixrindt added the dependencies Pull requests that update a dependency file label Oct 23, 2023
@jeriox
Copy link
Contributor Author

jeriox commented Jan 27, 2024

blocked by django-tenants/django-tenants#959

this is merged and released in 3.6 of django-tenants

@felixrindt
Copy link
Member

@felixrindt
Copy link
Member

@dependabot rebase

@felixrindt
Copy link
Member

We found out that Cursors in pscopg3 use a threading.Lock on the Connection object to execute queries. Inside the lock, field values are serialized. What happens in the ModelLogging module is

  • we try to save a logged object
  • in the post_save signal, saving of a LogEntry is triggered
  • LogEntry is saved, and only inside a block protected by the lock, the JSON field contents are serialized
  • our custom JSONserializer executes a query to get a contenttype
  • that query uses the same connection object, which is locked by the LogEntry save, and thus we get a deadlock

We don't know why the value serialization happens inside the connection lock yet. Seams like this is before any DB interaction, but maybe it's needed for psycopgs implementation to be threadsafe. Thus, we need to move the serialization outside the lock (before we call save) or avoid queries (with that locked connection) inside our serialization method.

This could be done using

  1. The already committed monkey patch/workaround, which serializes json content before the the query is executed.
  2. A custom json field that does that.
  3. ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to psycopg3

4 participants