#33341: The PrimaryKey of an Unmanaged Model is incorrectly regognized
(accessing
database VIEW)
-------------------------------------+-------------------------------------
Reporter: Hukkinen | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.2
Uncategorized | Keywords: Unmanaged model,
Severity: Normal | Database VIEW, postgres
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have used the following method earlier successfully with Django 3.0.6,
but now there's a bug.
But now the 3.2.9 catches a "Gotcha" in django/db/models/fields/related.py
in "get_instance_value_for_fields" (line 662), I believe incorrectly.
Currently I have:
– A view on postgres (to access a managed model "Rules", with default id
as PK): CREATE OR REPLACE VIEW rules_view
– Unmanaged model to access "Rules" data via "rules_view" view like this:
{{{
class LinkedRules(Rules)
....
class Meta:
managed = False
db_table = 'rules_view
}}}
The problem: I am able to retrieve the data with, only with a raw SQL
query, after changing the field name from id to rules_ptr_id like this:
{{{
LinkedViewRules.objects.raw(f'SELECT id as rules_ptr_id , ...
}}}
Hope this helps.
PS. Couldn't test my current project with old <3.2 version, due to other
incompatibilities (with numpy array withespaces).
(Table names are paraphrased, hopefully without errors)
Hint from django/db/models/fields/related.py:
# Gotcha: in some cases (like fixture loading) a model can
have
# different values in parent_ptr_id and parent's id. So, use
# instance.pk (that is, parent_ptr_id) when asked for
instance.id.
--
Ticket URL: <https://code.djangoproject.com/ticket/33341>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.b01a75751777e444d621b433687d0c18%40djangoproject.com.