Skip to content

Conversation

@goodtune
Copy link
Collaborator

@goodtune goodtune commented Sep 4, 2025

This PR implements the missing get_sequences() method in the tenant schemas database introspection class to fix Django 4.2+ compatibility issues.

Problem

Issue #538 reports that running certain Django commands (like flush) fails with:
NotImplementedError: subclasses of BaseDatabaseIntrospection may require a get_sequences() method

This occurs because Django 4.2+ requires database backends to implement the get_sequences() method for introspection operations, but the tenant schemas backend was missing this implementation.

Solution

This PR provides:

1. Implementation of get_sequences() method

  • Added _get_sequences_query SQL that queries PostgreSQL system tables
  • Implemented get_sequences() method that returns sequence information for a given table
  • Method is schema-aware and works correctly within tenant contexts

2. Comprehensive Test Case

Testing

Before this fix: Test fails with NotImplementedError
After this fix: Test passes, confirming the implementation works correctly

Verified with tox test suite across multiple Python/Django combinations.

Credits

This implementation is based on the excellent work by:

Both provided identical, high-quality implementations. This PR consolidates their work with comprehensive testing.

Related

Co-authored-by: barkhabol [email protected]
Co-authored-by: shantanutomarr [email protected]

shantanutomarr and others added 4 commits March 24, 2025 12:50
- When running migrate_schemas command that applies a migration to change
the primary key field of a model from `AutoField` to `BigAutoField`, we
get the following error:

`NotImplementedError: subclasses of BaseDatabaseIntrospection may require a get_sequences() method`

- Apparently this method is not implemented in the tenant schemas
backend yet, but is expected by Django 4.2.
- This commit adds that method by refering to a pull request on the
original project,
bernardopires#567.
- Reproduces issue bernardopires#538 where get_sequences() method is missing
- Test directly calls introspection.get_sequences() to trigger NotImplementedError
- Demonstrates the bug that PR 705 fixes
- Reproduces issue bernardopires#538 where get_sequences() method is missing
- Test directly calls introspection.get_sequences() to trigger NotImplementedError
- Demonstrates the bug that PR 705 fixes
@goodtune goodtune changed the title Add comprehensive test case for get_sequences() introspection method Fix: Implement get_sequences() method for Django 4.2+ compatibility Sep 4, 2025
@goodtune goodtune changed the title Fix: Implement get_sequences() method for Django 4.2+ compatibility Fix: Implement get_sequences() method for Django 4.2+ compatibility Sep 4, 2025
@goodtune goodtune merged commit a59b5e7 into bernardopires:master Sep 4, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django db introspection get_sequences() NotImplementedError on flush

2 participants