Opened 7 years ago

Closed 7 years ago

#29001 closed Bug (needsinfo)

postgres connection hstore support can disappear in low memory situations

Reported by: Ronan Klyne Owned by:
Component: contrib.postgres Version: 1.8
Severity: Normal Keywords: postgres hstore signal weakref
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Present in 1.8 and master. Probably versions between but I haven't checked them all

In order to correctly handle hstore data on new connections Django registers a signal handler to the connection_created signal.

This signal is created as a weakref and can be garbage collected, causing all future connections to misbehave when receiving hstore data from Postgres.

This problem has also been seen and fixed in django-hstore - https://github.com/djangonauts/django-hstore/pull/128

Change History (4)

comment:2 by Tim Graham, 7 years ago

Easy pickings: unset

I don't know much about how garbage collection works in Python, but if this is indeed the correct solution, then perhaps some clarifications to Django's documentation would be useful. It says,"Django stores signal handlers as weak references by default. Thus, if your receiver is a local function, it may be garbage collected." but my understanding is that the receiver here (register_type_handlers) isn't a local function.

comment:3 by Ronan Klyne, 7 years ago

I honestly don't know enough about the GC to explain this properly in the docs but I have seen the problem happen in django-hstore. I was reading the Django code and saw the same pattern so I pushed the same fix as a PR here. At the very least it seemed like a more explicit description of the desired effect - I don't think we would ever want this signal handler to be garbage collected.

Django itself is using a module level function and django-hstore uses a module level singleton callable class. That's close enough that I would imagine that it's vulnerable to whatever peculiarity was breaking django-hstore, though I can't explain why the garbage collector would collect it.

When this problem occurs it manifests as an hstore field being set to a string value on the Model - the dictionary deserialisation is never triggered.

Maybe you just want to archive this until that situation arises in the wild?

comment:4 by Tim Graham, 7 years ago

Resolution: needsinfo
Status: newclosed

Sure, I think we should wait to fix a problem until we see it, so we can confirm the change is needed and that it fixes the issue. Thanks.

Note: See TracTickets for help on using tickets.
Back to Top