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(versioning): multiple versioned segment overrides added to environment document #3974

Merged

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

This PR fixes an issue found in testing where we were previously adding all versions of a given segment override to the environment document. It achieves this by (unfortunately) adding an extra query to the mapping function to grab the latest versions for an environment and then filtering out any segment overrides that don't have a matching version.

How did you test this code?

Added an explicit unit test on the mapper function to test it.

@matthewelwell matthewelwell requested a review from khvn26 May 17, 2024 09:11
Copy link

vercel bot commented May 17, 2024

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

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 1:05pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 1:05pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 17, 2024 1:05pm

Copy link
Contributor

github-actions bot commented May 17, 2024

Uffizzi Preview deployment-51882 was deleted.

Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.18%. Comparing base (c5aa610) to head (419d019).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3974   +/-   ##
=======================================
  Coverage   96.18%   96.18%           
=======================================
  Files        1141     1141           
  Lines       36507    36526   +19     
=======================================
+ Hits        35114    35133   +19     
  Misses       1393     1393           

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

Comment on lines 429 to 430
Iterable["EnvironmentFeatureVersion"] | None
) = None,
Copy link
Member

Choose a reason for hiding this comment

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

nit: optional argument is not needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

) -> Dict[int, List["FeatureState"]]:
feature_states_by_segment_id = {}
latest_environment_feature_versions = latest_environment_feature_versions or []
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Convert to set for faster membership checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we had to do an iteration to convert to a set, I ended up using a set of uuids instead of the object itself. This should give us an extra (very minor) boost in performance too I think.

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.

LGTM overall, requested a minor cleanup

@@ -419,14 +430,26 @@ def _get_prioritised_feature_states(
def _get_segment_feature_states(
segments: Iterable["Segment"],
environment_id: int,
latest_environment_feature_version_uuids: Iterable["EnvironmentFeatureVersion"],
Copy link
Member

Choose a reason for hiding this comment

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

The typing is incorrect here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gah, good spot! Fixing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@matthewelwell matthewelwell deleted the fix(versioning)/segment-overrides-in-environment-document branch May 17, 2024 14:40
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.

2 participants