Skip to content

Conversation

@Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented Apr 21, 2025

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

  • 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

  • Overriden update to use update_metadata method from SerializerWithMetadata inherited from common

How did you test this code?

  • Running tests against common
  • Manually (creating and updating custom metadata fields in env/segments/features)
  • Created a new test in segments_views failing on previous flagsmith-common version, passing now
FAILED tests/unit/segments/test_unit_segments_views.py::test_update_segment_metadata_create_correct_number_of_metadata[admin_client] - assert 1 == 2
FAILED tests/unit/segments/test_unit_segments_views.py::test_update_segment_metadata_create_correct_number_of_metadata[admin_master_api_key_client] - assert 1 == 2

https://www.loom.com/share/f980f034f6144c548a2f30efd809f828

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner April 21, 2025 17:09
@Zaimwa9 Zaimwa9 requested review from gagantrivedi and removed request for a team April 21, 2025 17:09
@vercel
Copy link

vercel bot commented Apr 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 May 7, 2025 5:17pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview May 7, 2025 5:17pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview May 7, 2025 5:17pm

@Zaimwa9 Zaimwa9 marked this pull request as draft April 21, 2025 17:09
@github-actions github-actions bot added api Issue related to the REST API fix labels Apr 21, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 21, 2025

Docker builds report

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

@github-actions
Copy link
Contributor

github-actions bot commented Apr 21, 2025

Uffizzi Preview deployment-62988 was deleted.

@github-actions github-actions bot added fix and removed fix labels Apr 22, 2025
@Zaimwa9 Zaimwa9 marked this pull request as ready for review April 22, 2025 14:08
@github-actions github-actions bot added fix and removed fix labels Apr 22, 2025
@Zaimwa9 Zaimwa9 changed the title fix: metadata-feature-env-changes-updates-existing-value fix: metadata-feature-changes-erases-existing-value Apr 22, 2025
Copy link
Contributor

@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.

In general, I'm a little confused by this PR (and the one in common). I'm not sure exactly what we're solving. Based on the changes that I See here, it feels like the metadata logic never would have previously worked for environments and features, but I don't think that's true, right?

Also, I don't see any additional tests added to this PR, or the one in the flagsmith-common repository. we should definitely add a test (or tests) somewhere.

environment = super().update(instance, validated_data)
self.update_metadata(environment, metadata_items) # type: ignore[no-untyped-call]
environment.refresh_from_db()
assert isinstance(environment, Environment)
Copy link
Contributor

Choose a reason for hiding this comment

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

This assertion feels unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually as of it is "necessary" for mypy because super().update is not fully typed and returns a models.Model. I can type it in a separate PR because it might need to type a couple of used functions inside

Copy link
Member

Choose a reason for hiding this comment

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

I'd at least hide it behind if typing.TYPE_CHECKING: to clearly state its purpose.

Ideally, i'd try annotating the var like so:

environment: Environment = super().update(instance, validated_data)

and see if mypy complains about it.

feature = super().update(instance, validated_data) # type: ignore[no-untyped-call]
self.update_metadata(feature, metadata_items)
feature.refresh_from_db()
assert isinstance(feature, Feature)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, this seems unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same typing issue

@github-actions github-actions bot added fix and removed fix labels Apr 28, 2025
@github-actions github-actions bot added fix and removed fix labels Apr 29, 2025
@github-actions github-actions bot added fix and removed fix labels Apr 30, 2025
@github-actions github-actions bot added fix and removed fix labels Apr 30, 2025
@codecov
Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.63%. Comparing base (3ad0124) to head (9640d4c).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5362   +/-   ##
=======================================
  Coverage   97.63%   97.63%           
=======================================
  Files        1239     1239           
  Lines       43065    43097   +32     
=======================================
+ Hits        42046    42078   +32     
  Misses       1019     1019           

☔ 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 fix and removed fix labels May 6, 2025
@Zaimwa9 Zaimwa9 requested a review from khvn26 May 6, 2025 15:03
@github-actions github-actions bot added fix and removed fix labels May 7, 2025
@github-actions github-actions bot added fix and removed fix labels May 7, 2025
@github-actions github-actions bot added fix and removed fix labels May 7, 2025
@Zaimwa9
Copy link
Contributor Author

Zaimwa9 commented May 7, 2025

Added new test case to assert the correct number of metadata is created.
Failing on previous common version (only one created), success now

FAILED tests/unit/segments/test_unit_segments_views.py::test_update_segment_metadata_create_correct_number_of_metadata[admin_client] - assert 1 == 2
FAILED tests/unit/segments/test_unit_segments_views.py::test_update_segment_metadata_create_correct_number_of_metadata[admin_master_api_key_client] - assert 1 == 2

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.

Looks good 👍

@Zaimwa9 Zaimwa9 merged commit 055644f into main May 8, 2025
32 checks passed
@Zaimwa9 Zaimwa9 deleted the fix/update-metadata-value-from-entity branch May 8, 2025 13:57
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.

4 participants