Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: odd behaviour seen when using REPLICA_DATABASE_URLS #3771

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

matthewelwell
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Fixes #3681.

How did you test this code?

Ran the API locally with REPLICA_DATABASE_URLS set up to point to the same database as DATABASE_URL and observed that, without this change, I received an exception when trying to create a Feature.

Once I made this change, I no longer received the exception.

Copy link

vercel bot commented Apr 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Apr 15, 2024 7:03pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 7:03pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 7:03pm

@matthewelwell
Copy link
Contributor Author

@zachaysan @khvn26 I am requesting a review from both of you on this PR. Zach, because you have the context from our investigation of this issue. Kim, because you might have some context as to why history_instance.instance was used in the first place, rather than just instance.

Copy link
Contributor

github-actions bot commented Apr 15, 2024

Uffizzi Preview deployment-50192 was deleted.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.91%. Comparing base (cc88dab) to head (1083c8e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3771   +/-   ##
=======================================
  Coverage   95.91%   95.91%           
=======================================
  Files        1102     1102           
  Lines       34782    34782           
=======================================
  Hits        33362    33362           
  Misses       1420     1420           

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

Copy link
Contributor

@zachaysan zachaysan left a comment

Choose a reason for hiding this comment

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

I'm happy to see this fixed, but we really should make a ticket for creating a test suite to run with a replica read database in addition to running the whole suite as just the default database. I know 99% of the time it would just duplicate the work, but the small part of the time to catch these regressions would really help out to find issues for our clients that use the replica databases.

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Approved but echoing Zach's proposal here. I'm sure we're going to bump into problems with replicated setups in the future, see https://andrewbrookins.com/python/scaling-django-with-postgres-read-replicas/ ("Solving Consistency Problems Caused By Replication Lag").

@matthewelwell
Copy link
Contributor Author

matthewelwell commented Apr 17, 2024

@zachaysan @khvn26 yeah, you're both right for sure. I hoped it would be as simple as e.g.:

DATABASE_URL=postgres://postgres:[email protected]:5432/flagsmith \
 REPLICA_DATABASE_URLS=postgres://postgres:[email protected]:5432/flagsmith \
 pytest

but this causes all the tests to fail with a spurious error:

ERROR tests/integration/ core/test_commands.py::test_bootstrap__empty_instance__creates_expected - django.db.utils.ProgrammingError: column users_ffadminuser.organisation_id does not exist

I agree we should implement some testing against this, but it looks like it needs some thought.

@matthewelwell matthewelwell added this pull request to the merge queue Apr 17, 2024
Merged via the queue into main with commit ec9e8ab Apr 17, 2024
23 checks passed
@matthewelwell matthewelwell deleted the fix/500-errors-with-replica-db-configured branch April 17, 2024 14:51
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After upgrade from v2.66.2 to 2.104.0 some POST calls fail when REPLICA_DATABASE_URLS is set
4 participants