Weird DB failure after upgrade to django-tenants 3.4.4 & Django 4.1
See original GitHub issueI am using containerized Postgres as my database:
centos/postgresql-12-centos7 latest ead3e66c2b54 12 months ago 372MB
this hasn’t changed recently and was working fine in previous commits.
After upgrade from django-tenants 3.4.3 to 3.4.4 (and other updates to the app which gets split into tenants, including upgrade to Django 4.1) I am seeing a failure in my automated tests:
psycopg2.errors.RaiseException: Action: PRIVS: Sequences Diagnostics: line=SQL statement "GRANT SELECT ON subscriber.management_build_build_id_seq TO "kiwi";"
PL/pgSQL function clone_schema(text,text,boolean,boolean) line 606 at EXECUTE. 42P01. relation "subscriber.management_build_build_id_seq" does not exist
CONTEXT: PL/pgSQL function clone_schema(text,text,boolean,boolean) line 669 at RAISE
Full logs: https://github.com/kiwitcms/tenants/runs/7725825769?check_suite_focus=true
Test which triggers this failure: https://github.com/kiwitcms/tenants/blob/master/tcms_tenants/tests/test_views.py#L117
which fails here https://github.com/kiwitcms/tenants/blob/master/tcms_tenants/utils.py#L93 - executing clone_tenant
command!
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Bug with Django 4.1: DETAIL: Key (id)=(1) already exists. #831
You will get a failure telling you that the primary key for this record already exists! Background: In Django 4.1 and later the...
Read more >Databases — Django 4.1.4 documentation
Django officially supports the following databases: ... Django opens a connection to the database when it first makes a database query.
Read more >Django Bulgaria - Facebook
Django Meetup - Google Compute Engine management in a Django-based app by Pavel ... Weird DB failure after upgrade to django-tenants 3.4.4 &...
Read more >django-tenants - PyPI
This application enables django powered websites to have multiple tenants via PostgreSQL schemas. A vital feature for every Software-as-a-Service (SaaS) ...
Read more >django-SHOP - Read the Docs
Compared to other e-commerce solutions, the django-SHOP framework has a rather small footprint in terms of code lines, database tables and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sequences are used to create primary keys. In most recent versions of PostgreSQL, there’s a new thing called identifiers thwt no longer make use of sequences, so maybe django started to use them instead. But it’s hard to tell without having a look into the database.
More info:
When using Django 4.1 to initialize the database this snippet returns 0 sequences
as a result 0 new sequences are created when cloning. While this next snippet returns quite a lot of records
and tries to grant permissions on sequences which it thinks should exist.
If I comment out the snippet above I don’t get the error and new tenants are created successfully. I was able to add new records into the newly created tenant. Primary keys for the newly added records seem to be automatically updated.
What bothers me is that half of the queries select from
information_schema
and the other half frompg_catalog
. Postgres documentation sayswhich IMO means we should try using only one of these sources of information, not both.
@tomturner, @SrNetoChan can you please comment a bit more on my findings? What do you make of it?
Note: I can easily disable the conflicting snippet of SQL code by introducing a condition around the number of sequences copied which should be an easy fix.