Skip to content

Conversation

@matthewelwell
Copy link
Contributor

@matthewelwell matthewelwell commented Dec 31, 2025

Changes

Note: depends on Flagsmith/flagsmith-common#149

Upgrade to django 5.

There were seemingly very few changes that were needed, and most of the updates in this PR relate to typing updates which I've tried to fix where possible but erred on the side of type: ignore comments where needed.

The main breaking changes that required handling on our end were:

  1. Model.Meta.index_together was removed. I've replaced usages of this with models.Index(fields=[...]). This change does result in a migration applied to the database in the form of a RenameIndex but from what I can tell, this is a very minor operation and doesn't require any locks on the data in the table, or the index, only on the metadata for the table.
  2. django.utils.timezone.utc was removed. I've replaced this with datetime.timezone.utc, but since we still want to use django.utils.timezone for other logic, (e.g. timezone.now()), I've imported datetime.timezone as dttz where needed.

I also had to update a few dependencies to support the django upgrade:

  1. django-debug-toolbar
  2. django-softdelete
  3. djoser

Note that the upgrade of django-debug-toolbar meant that I needed to remove DEBUG = True from the test settings (conversation on the actual LoC for clarification).

How did you test this code?

Unit tests, and running locally.

@vercel
Copy link

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Review Updated (UTC)
docs Ignored Ignored Preview Jan 2, 2026 11:35am
flagsmith-frontend-preview Ignored Ignored Preview Jan 2, 2026 11:35am
flagsmith-frontend-staging Ignored Ignored Preview Jan 2, 2026 11:35am

@github-actions github-actions bot added the api Issue related to the REST API label Dec 31, 2025
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.08%. Comparing base (ed2f460) to head (2f5b58e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6452      +/-   ##
==========================================
+ Coverage   98.06%   98.08%   +0.01%     
==========================================
  Files        1292     1295       +3     
  Lines       46509    46515       +6     
==========================================
+ Hits        45611    45622      +11     
+ Misses        898      893       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Dec 31, 2025
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Jan 2, 2026
Copy link
Contributor Author

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

Minor comments for context where needed.


ENABLE_POSTPONE_DECORATOR = False

DEBUG = True
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After the upgrade of django-debug-toolbar, this was causing issues because we only include the debug toolbar if DEBUG is True (see here). As I understand it, it's because we don't also add it to installed_apps here which is now required (but seemingly wasn't in older versions of the package).

I decided the better solution here was simply to remove the DEBUG = True as I'm not sure why it existed here for tests in the first place.

Comment on lines +13 to +17
migrations.RenameIndex(
model_name="apiusageraw",
new_name="app_analyti_environ_b61cad_idx",
old_fields=("environment_id", "created_at"),
),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caused by deprecation of Model.Meta.index_together. I've researched and, as I understand it, it requires a lock on the metadata, but no the table or index itself.

Since we don't reference the name of the index directly (although we might in specific oracle migrations 🤔) we shouldn't have any schema mismatch issues.

Comment on lines +14 to +15
if serialized_codes is None: # pragma: no cover
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added for typing reasons.

feature=feature_health_event.feature,
environment=feature_health_event.environment,
type=FeatureHealthEventType.HEALTHY,
type=FeatureHealthEventType.HEALTHY.value,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was somewhat odd. I can't see any indication of any changes to this behaviour in the notes here, but looking at this test I do think it was wrong previously anyway.

The error that I was seeing was that it couldn't create the event with the type as the literal string "FeatureHealthEventType.HEALTHY" which makes sense - perhaps Django 5 is more strict on enforcing the choices behaviour. Either way, I think this change is a good step.

Comment on lines +2 to +3
# Note: This migration is a no-op, and just adds the `through_fields` attribute
# seemingly needed by the state in django5
Copy link
Contributor Author

@matthewelwell matthewelwell Jan 2, 2026

Choose a reason for hiding this comment

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

This migration is a no-op as per this comment.

length: int = 10,
allowed_chars: str = string.ascii_letters + string.digits,
) -> str:
return "".join(secrets.choice(allowed_chars) for _ in range(length))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make_random_password was removed. I simply re-added it, using the guidance provided here.

djangorestframework-dataclasses = "^1.3.1"
pyotp = "^2.9.0"
flagsmith-common = "^2.2.7"
flagsmith-common = { git = "https://github.com/flagsmith/flagsmith-common", branch = "deps/django-5-upgrade" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: replace this with the new version once released.

@matthewelwell matthewelwell marked this pull request as ready for review January 2, 2026 11:51
@matthewelwell matthewelwell requested a review from a team as a code owner January 2, 2026 11:51
@matthewelwell matthewelwell requested review from gagantrivedi and removed request for a team January 2, 2026 11:51
@github-actions github-actions bot added dependencies Pull requests that update a dependency file and removed dependencies Pull requests that update a dependency file labels Jan 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6452 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6452 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6452 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6452 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6452 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6452 Finished ✅ Results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants