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

feat: Identity overrides in environment document #3766

Merged
merged 6 commits into from May 15, 2024

Conversation

khvn26
Copy link
Member

@khvn26 khvn26 commented Apr 15, 2024

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 adds identity overrides to the environment document response for local evaluation.

How did you test this code?

Added a unit test for the new mapper.

Contributes to #1762.

@khvn26 khvn26 requested review from a team and novakzaballa and removed request for a team April 15, 2024 08:40
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 🛑 Canceled (Inspect) May 14, 2024 5:42pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 5:42pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 14, 2024 5:42pm

Copy link
Contributor

github-actions bot commented Apr 15, 2024

Uffizzi Preview deployment-50125 was deleted.

@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.99%. Comparing base (97df705) to head (2899fd1).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3766   +/-   ##
=======================================
  Coverage   95.99%   95.99%           
=======================================
  Files        1135     1138    +3     
  Lines       36204    36245   +41     
=======================================
+ Hits        34754    34795   +41     
  Misses       1450     1450           

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

Comment on lines 44 to 47
result = map_environment_to_sdk_document(
environment,
identities_with_overrides=identities_with_overrides,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd love to see an assertion on the number of queries here (along with maybe multiple identities / identity overrides).

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a valid request but the assertion won't belong to the mapper test as it expects already fetched data with the identities_with_overrides kwarg. I'll add multiple overrides to the environment-document view test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, and fixed an N+1 issue in the process 😬

api/util/mappers/engine.py Show resolved Hide resolved
"identity",
"identity__environment",
).prefetch_related(
"identity__identity_traits",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure why we would need traits here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought I had fair reasoning for that, but, upon reviewing, I tend to agree with your question/comment. Removed both trait prefetching and trait mapping to the environment document.

Comment on lines 353 to 354
- In circumstances where you need to target a specific identity, you can do this by creating a segment to target that
specific user and subsequently adding a segment override for that segment.
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're removing this, shouldn't we also remove this line: https://github.com/Flagsmith/flagsmith/pull/3766/files#diff-a4321d583bb04a398f14c6f6164fe85200d8687ac5c617f8e52b631376463809L349

... but should we also add some data about the Edge API opt-in process here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed Ben's commit as we should really update the docs as part of FE work after #3881.

 - Add `map_environment_to_sdk_document` mapper
 - Add `Identity.objects.with_overrides()`
- Use INNER JOIN for identity overrides
- Don't fetch integrations for the SDK endpoint
@khvn26 khvn26 added this pull request to the merge queue May 15, 2024
Merged via the queue into main with commit e8d1337 May 15, 2024
24 checks passed
@khvn26 khvn26 deleted the feat/environment-document-identity-overrides branch May 15, 2024 14: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 docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants