#34344 closed Cleanup/optimization (fixed)

PostGIS Database Backend Overrides features_class, ops_class and introspection_class

Reported by: David Buhler Owned by: David Buhler
Component: GIS Version: dev
Severity: Normal Keywords: geodjango postgis database backend
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While working on adding PostGIS support to the django-multitenant library I had some issues with the features_class that was overridden in the DatabaseWrapper subclass. After some troubleshooting I was able to determine this is because the PostGIS backend explicitly sets the features, ops, and introspection properties to the file local classes:

https://github.com/django/django/blob/stable/4.2.x/django/contrib/gis/db/backends/postgis/base.py#L91

I was able to work around this behaviour by overriding the constructor and setting the features property explicitly:

https://github.com/citusdata/django-multitenant/pull/150/files#diff-0d077af5d4e86f31f478785458ea6a03768a15aea077f49b9a79ffca8b0fe4beR37

This isn't very intuitive as other database backends will respect setting the _class properties to instantiate classes.

Change History (8)

comment:1 by David Buhler, 19 months ago

Here is a patch to fix the issue: https://github.com/django/django/pull/16563

comment:2 by Mariusz Felisiak, 19 months ago

Resolution: needsinfo
Status: newclosed

Thanks for this ticket, however using features_class, ops_class, and introspection_class will cause initializing PostGIS stuff for non-db connections (see 7e714827ead50f77aa82394cc2511ff96ab67fa4 and #16969) as they will be initialized in PsycopgDatabaseWrapper.__init__() and NO_DB_ALIAS-branch doesn't change anything anymore. Is there a way to use features_class, ops_class, and introspection_class in a backward compatible way?

comment:3 by David Buhler, 19 months ago

Hello Mariusz, I've updated the PR to be backwards compatible. In the init method I've reset the *_class properties to the original postgresql versions and moved the call to super().__init__(*args, **kwargs) to below the conditional check for NO_DB_ALIAS.

comment:4 by David Buhler, 19 months ago

Resolution: needsinfo
Status: closednew

comment:5 by David Buhler, 19 months ago

Owner: changed from nobody to David Buhler
Status: newassigned

comment:6 by Mariusz Felisiak, 19 months ago

Has patch: unset
Triage Stage: UnreviewedAccepted

comment:7 by Mariusz Felisiak, 19 months ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 19 months ago

Resolution: fixed
Status: assignedclosed

In a91e59e:

Fixed #34344 -- Allowed PostGIS DatabaseWrapper subclasses to customize (features/introspection/ops)_class classes.

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