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): fix cloning environments using v2 versioning #3999

Merged
merged 5 commits into from
May 21, 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

This fixes an issue found in testing when cloning an environment that has enabled v2 versioning.

How did you test this code?

Added a unit test for cloning an environment using v2 versioning.

Copy link

vercel bot commented May 21, 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 21, 2024 8:31pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 8:31pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 8:31pm

Copy link

sentry-io bot commented May 21, 2024

🔍 Existing Issues For Review

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

📄 File: api/features/versioning/models.py

Function Unhandled Issue
publish ValueError: Cannot assign "<api_keys.user.APIKeyUser object at 0x7fcc2f212f30>": "EnvironmentFeatureVersion.p... /api/v1/environmen...
Event Count: 1

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

Copy link
Contributor

github-actions bot commented May 21, 2024

Uffizzi Preview deployment-52111 was deleted.

@matthewelwell matthewelwell marked this pull request as ready for review May 21, 2024 19:43
@matthewelwell matthewelwell requested review from a team and zachaysan and removed request for a team May 21, 2024 19:43
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.22%. Comparing base (16d1dda) to head (655a9cf).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3999   +/-   ##
=======================================
  Coverage   96.21%   96.22%           
=======================================
  Files        1142     1142           
  Lines       36724    36760   +36     
=======================================
+ Hits        35335    35371   +36     
  Misses       1389     1389           

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

Comment on lines 35 to 40
return self.filter(
uuid__in=[
efv.uuid
for efv in EnvironmentFeatureVersion.objects.get_latest_versions(self)
]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not particularly happy with this, but the alternative was to update the sql to return all the fields and then (in the Environment.clone method) manually create the EnvironmentFeatureVersion, rather than using a clone method on the model class. To keep things consistent with other models, this seemed like the lesser of 2 evils.

Copy link
Member

Choose a reason for hiding this comment

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

Why not write a second sql with all the fields?

manually create the EnvironmentFeatureVersion, rather than using a clone method on the model class

I don't think so as long as the model instances were correctly mapped?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that "Cloning environments" is not used frequently enough to make this a real issue.

Copy link
Member

Choose a reason for hiding this comment

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

Fair point Novak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that "Cloning environments" is not used frequently enough to make this a real issue.

Well, I wish this were true. But the FE made the decision to remove the functionality to 'create' an environment, and now all environments are cloned from another.

Why not write a second sql with all the fields?

I'd still rather avoid this to avoid code duplication or hacky ways of concatenating SQL strings.

Copy link
Contributor

@novakzaballa novakzaballa left a comment

Choose a reason for hiding this comment

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

LGTM

@matthewelwell matthewelwell force-pushed the fix(versioning)/clone-environment branch from ba65782 to 655a9cf Compare May 21, 2024 20:21
@matthewelwell matthewelwell added this pull request to the merge queue May 21, 2024
Merged via the queue into main with commit eef02fb May 21, 2024
24 checks passed
@matthewelwell matthewelwell deleted the fix(versioning)/clone-environment branch May 21, 2024 21:50
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.

3 participants