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: Raise if environment_feature_version is None #5028

Merged
merged 7 commits into from
Jan 22, 2025

Conversation

zachaysan
Copy link
Contributor

Changes

Solves this Sentry alert. Elsewhere in this part of the codebase we raise value errors to deal with bad input. Rather than erroring out with a type error that looks like a bug, we should raise an error of our own to deal with it.

How did you test this code?

One new test.

@zachaysan zachaysan requested a review from a team as a code owner January 21, 2025 16:34
@zachaysan zachaysan requested review from matthewelwell and removed request for a team January 21, 2025 16:34
Copy link

vercel bot commented Jan 21, 2025

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 4:38pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 4:38pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2025 4:38pm

@github-actions github-actions bot added the api Issue related to the REST API label Jan 21, 2025
@zachaysan zachaysan requested review from khvn26 and removed request for matthewelwell January 21, 2025 16:34
Copy link

sentry-io bot commented Jan 21, 2025

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: api/features/models.py

Function Unhandled Issue
__gt__ TypeError: '>' not supported between instances of 'NoneType' and 'EnvironmentFeatureVersion' ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot added the fix label Jan 21, 2025
Copy link
Contributor

github-actions bot commented Jan 21, 2025

Docker builds report

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

Copy link
Contributor

github-actions bot commented Jan 21, 2025

Uffizzi Preview deployment-60117 was deleted.

api/conftest.py Outdated Show resolved Hide resolved
api/conftest.py Outdated Show resolved Hide resolved
@khvn26
Copy link
Member

khvn26 commented Jan 21, 2025

Do we have any idea how we reached the faulty state in the first place?

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.40%. Comparing base (33cabfc) to head (b2419c0).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5028   +/-   ##
=======================================
  Coverage   97.40%   97.40%           
=======================================
  Files        1192     1192           
  Lines       41657    41665    +8     
=======================================
+ Hits        40574    40582    +8     
  Misses       1083     1083           

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

zachaysan and others added 2 commits January 22, 2025 09:01
Co-authored-by: Kim Gustyr <kim.gustyr@flagsmith.com>
Co-authored-by: Kim Gustyr <kim.gustyr@flagsmith.com>
@github-actions github-actions bot added fix and removed fix labels Jan 22, 2025
@github-actions github-actions bot added fix and removed fix labels Jan 22, 2025
@zachaysan
Copy link
Contributor Author

Do we have any idea how we reached the faulty state in the first place?

No but we did somehow.

Comment on lines 929 to 938
assert tuple((user["id"], user["group_admin"]) for user in group_2_users) == (
(user1.pk, False),
(user2.pk, True),
)

for user in group_2_users:
if user["id"] == user1.pk:
assert user["group_admin"] is False
continue
if user["id"] == user2.pk:
assert user["group_admin"] is True
continue
# We should only match the two users.
assert False
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'm pretty sure using sets will solve this in a neater way:

    assert set((user["id"], user["group_admin"]) for user in group_2_users) == {
        (user1.pk, False),
        (user2.pk, True),
    }

You won't have to maintain the uncovered assert False line too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh this is a much better approach. Thank you!!

@github-actions github-actions bot added fix and removed fix labels Jan 22, 2025
@zachaysan zachaysan merged commit edd7141 into main Jan 22, 2025
37 checks passed
@zachaysan zachaysan deleted the fix/raise_if_environment_feature_version_is_none branch January 22, 2025 16:59
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 fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants