[Django] #34344: PostGIS Database Backend Overrides features_class, ops_class and introspection_class

29 views
Skip to first unread message

Django

unread,
Feb 16, 2023, 4:38:20 PM2/16/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: davidjayb | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: GIS | Version: dev
Severity: Normal | Keywords: geodjango postgis
Triage Stage: | database backend
Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34344>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 16, 2023, 4:39:14 PM2/16/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: davidjayb | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: GIS | Version: dev
Severity: Normal | Resolution:

Keywords: geodjango postgis | Triage Stage:
database backend | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by davidjayb):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:1>

Django

unread,
Feb 16, 2023, 11:48:13 PM2/16/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: GIS | Version: dev
Severity: Normal | Resolution: needsinfo

Keywords: geodjango postgis | Triage Stage:
database backend | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => needsinfo


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:2>

Django

unread,
Feb 20, 2023, 12:55:47 PM2/20/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: GIS | Version: dev
Severity: Normal | Resolution: needsinfo
Keywords: geodjango postgis | Triage Stage:
database backend | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by David Buhler):

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`.

--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:3>

Django

unread,
Feb 20, 2023, 12:55:56 PM2/20/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: nobody
Type: | Status: new

Cleanup/optimization |
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: geodjango postgis | Triage Stage:
database backend | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Buhler):

* status: closed => new
* resolution: needsinfo =>


--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:4>

Django

unread,
Feb 20, 2023, 12:56:04 PM2/20/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: David
Type: | Buhler
Cleanup/optimization | Status: assigned

Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: geodjango postgis | Triage Stage:
database backend | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Buhler):

* owner: nobody => David Buhler
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:5>

Django

unread,
Feb 20, 2023, 2:22:48 PM2/20/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: David
Type: | Buhler
Cleanup/optimization | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: geodjango postgis | Triage Stage: Accepted
database backend |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 1 => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:6>

Django

unread,
Feb 21, 2023, 2:56:09 AM2/21/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: David
Type: | Buhler
Cleanup/optimization | Status: assigned
Component: GIS | Version: dev
Severity: Normal | Resolution:
Keywords: geodjango postgis | Triage Stage: Ready for
database backend | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/16580 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:7>

Django

unread,
Feb 21, 2023, 3:26:48 AM2/21/23
to django-...@googlegroups.com
#34344: PostGIS Database Backend Overrides features_class, ops_class and
introspection_class
-------------------------------------+-------------------------------------
Reporter: David Buhler | Owner: David
Type: | Buhler
Cleanup/optimization | Status: closed
Component: GIS | Version: dev
Severity: Normal | Resolution: fixed

Keywords: geodjango postgis | Triage Stage: Ready for
database backend | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a91e59e4a0fa9cbc6c662feaad6ac17b0f07ce9a" a91e59e]:
{{{
#!CommitTicketReference repository=""
revision="a91e59e4a0fa9cbc6c662feaad6ac17b0f07ce9a"
Fixed #34344 -- Allowed PostGIS DatabaseWrapper subclasses to customize
(features/introspection/ops)_class classes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34344#comment:8>

Reply all
Reply to author
Forward
0 new messages