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

Connection features with @cached_property are not implemented properly #8

Closed laymonage closed 4 years ago

laymonage commented 4 years ago

@cached_property is only evaluated if it's attached to an instance. The current feature checks are implemented by mapping connection.vendor to the [vendor]Features class es. However, since we don't create an instance of the [vendor]Features classes, calling features[connection.vendor].feature_name returns a cached_property object, not the evaluated value.

A better implementation would be to use @receiver(connection_created) and use setattr() to add JSON features to connection.features, so that feature checks would be similar to the built-in JSONField.

It's probably a good idea to also add another test matrix with a database that does not support JSONField.