Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
It changes fundamental flag-field storage/constraint semantics across backends and migrations, so it warrants final human review despite the added test coverage.
Pull request overview
This PR updates django-enum’s flag-field storage model so that the sign bit of 16/32/64-bit integer columns is usable as a flag (two’s complement encoding in signed columns), primarily to remain compatible with Python 3.15’s behavior around negative flag values.
Changes:
- Flag fields now store full-width flags in signed integer columns via two’s complement, rejecting negative-valued flag enums and adjusting validators/constraints accordingly.
- Fixes/adjusts ORM bitwise behavior (notably
has_allon MySQL/MariaDB) and documents the requiredValue(..., output_field=...)wrapping forF()expressions when the top bit is involved. - Adds new/updated tests and legacy migration coverage to ensure data written by django-enum 2.x remains readable after upgrading.
File summaries
| File | Description |
|---|---|
src/django_enum/fields.py |
Implements two’s complement storage for flag fields, adds db_bit_length, updates constraint generation and validation. |
src/django_enum/fields.pyi |
Updates stubs/docs to reflect signed-column storage and new db_bit_length API. |
src/django_enum/query.py |
Adjusts has_all SQL for MySQL/MariaDB by casting bitwise results back to signed for correct comparisons with sign-bit flags. |
tests/test_sign_bit.py |
Adds focused tests for top-bit conversions, storage, querying, and constraint behavior. |
tests/test_legacy_migrations.py |
Adds migration regression tests to ensure 2.x-written data round-trips correctly after 3.x migrations. |
tests/settings.py |
Enables the new legacy migrations test app. |
tests/legacy_migrations/** |
Adds v2 model/settings scaffolding, frozen legacy migration, and the current models/migration for upgrade testing. |
tests/test_flags.py |
Updates bitwise F() expression tests to wrap RHS values where necessary; adjusts expected counts and unsupported lookup coverage. |
tests/test_field_types.py / tests/test_constraints.py / tests/test_field_types_ep.py / tests/test_flags_ep.py |
Updates expectations for signed integer storage and renamed “top-bit” enums. |
tests/djenum/models.py / tests/djenum/enums.py / tests/enum_prop/models.py / tests/enum_prop/enums.py |
Replaces negative-valued flag enums with non-negative top-bit variants consistent with the new storage rules. |
tests/*/migrations/*.py |
Regenerates test migrations to reflect the new field types/constraints and enum changes. |
doc/source/howto/flags.rst |
Documents full-width flag behavior and the F()/Value() requirement, plus MySQL/MariaDB limitations. |
doc/source/changelog.rst |
Adds v3.0.0 changelog details for the flag-field behavior change and upgrade implications. |
justfile |
Adds scripts to regenerate test migrations and frozen legacy migrations deterministically. |
.gitignore |
Adds .claude to ignored files. |
Review details
- Files reviewed: 32/36 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.