Skip to content

flags are now constrained to unsigned - compat with py 3.15 - #217

Open
bckohan wants to merge 2 commits into
django-commons:mainfrom
bckohan:int_flags
Open

bckohan wants to merge 2 commits into
django-commons:mainfrom
bckohan:int_flags

Conversation

@bckohan

@bckohan bckohan commented Sep 6, 2026

Copy link
Copy Markdown
Member

No description provided.

Copilot AI lite review requested due to automatic review settings September 6, 2026 23:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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_all on MySQL/MariaDB) and documents the required Value(..., output_field=...) wrapping for F() 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

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/django_enum/fields.py 100.00% <100.00%> (ø)
src/django_enum/query.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants