laymonage / django-jsonfield-backport

Backport of the cross-DB JSONField model and form fields from Django 3.1.
https://pypi.org/project/django-jsonfield-backport
BSD 3-Clause "New" or "Revised" License
42 stars 6 forks source link

Fix DatabaseFeatures issue for management commands and shell #39

Closed josterpi closed 2 years ago

josterpi commented 3 years ago

While it works in production and with runserver, JSONFieldConfig.ready() is getting called after the connection_created signal has been sent while running a management command or a shell. So, extend_features() never gets called.

To solve this, we check to see if the connection is_usable and extend_features immediately if it is. If not, register with the connection_created signal and wait until that is sent.

I wasn't sure if the right place to put this was in the ready() method or in connect_signal_receivers(), so I picked one. I'd be happy to put it somewhere else.

josterpi commented 3 years ago

Whoops, I'm looking into these failures, and in fact noticed in my own project that it's not working quite as expected.

BallisticPain commented 2 years ago

@laymonage I will attempt to manually implement these changes in my project to ascertain whether they work. I have a Django shell query that isn't working and I'm trying to use the Django shell to debug a production issue... so I'll let you know shortly if this works.

BallisticPain commented 2 years ago

@laymonage

I confirmed this fixed my issue in the shell. I hope that's helpful. For now it helps me as I can continue my production debugging.

Let me know if I can assist further! Thank you for this library and your efforts on it!!!

paul-hansen commented 2 years ago

This is also causing me grief. Can't debug an issue in production. I checked out josterpi's branch locally and it fixed the issue in the python shell at least.

@laymonage what would it take to get this merged and a new release? Anything we can help with?

paul-hansen commented 2 years ago

Wasn't expecting it that quick, thanks a ton!

josterpi commented 2 years ago

Yes, thank you! I came up with this pull request when it was causing me grief, but then I got pulled away to other things and haven't had any more time for it.