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(github-4555): use api_key name for changed_by #4561

Merged
merged 3 commits into from
Sep 4, 2024
Merged

Conversation

gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Aug 30, 2024

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

Fix the issue with updating feature states for edge identities using the API key by setting the changed_by webhook field to the name of the key.

How did you test this code?

Updates unit tests

@gagantrivedi gagantrivedi requested a review from a team as a code owner August 30, 2024 04:40
@gagantrivedi gagantrivedi requested review from khvn26 and removed request for a team August 30, 2024 04:40
Copy link

vercel bot commented Aug 30, 2024

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 Sep 4, 2024 9:09am
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Sep 4, 2024 9:09am
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Sep 4, 2024 9:09am

Copy link

sentry-io bot commented Aug 30, 2024

🔍 Existing Issues For Review

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

📄 File: api/edge_api/identities/serializers.py

Function Unhandled Issue
save AttributeError: 'APIKeyUser' object has no attribute 'id' /api/v1/environments/{environment_api_key}/edge-identities/{edge_identity_identity_uuid}/edge-featu...
Event Count: 1.6k

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

@github-actions github-actions bot added the api Issue related to the REST API label Aug 30, 2024
Copy link
Contributor

github-actions bot commented Aug 30, 2024

Docker builds report

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

@github-actions github-actions bot added the fix label Aug 30, 2024
Copy link
Contributor

github-actions bot commented Aug 30, 2024

Uffizzi Preview deployment-55730 was deleted.

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.14%. Comparing base (3b20df1) to head (f8ca4df).
Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4561   +/-   ##
=======================================
  Coverage   97.14%   97.14%           
=======================================
  Files        1154     1154           
  Lines       39811    39846   +35     
=======================================
+ Hits        38674    38709   +35     
  Misses       1137     1137           

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

@gagantrivedi gagantrivedi linked an issue Aug 30, 2024 that may be closed by this pull request
@gagantrivedi gagantrivedi requested review from khvn26, a team and matthewelwell September 3, 2024 09:02
Copy link
Contributor

@zachaysan zachaysan left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a couple of comments.

Comment on lines 55 to 69
mocker, identity, feature, admin_user
mocker,
identity,
feature,
user,
rf: RequestFactory,
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing typing

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

@github-actions github-actions bot added fix and removed fix labels Sep 4, 2024
@gagantrivedi gagantrivedi added this pull request to the merge queue Sep 4, 2024
Merged via the queue into main with commit 7ae2623 Sep 4, 2024
35 checks passed
@gagantrivedi gagantrivedi deleted the fix/4555 branch September 4, 2024 12:17
@@ -189,7 +186,7 @@ def save(self, **kwargs):
"environment_api_key": identity.environment_api_key,
"identity_id": identity.id,
"identity_identifier": identity.identifier,
"changed_by_user_id": request.user.id,
"changed_by": str(request.user),
Copy link
Contributor

Choose a reason for hiding this comment

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

@gagantrivedi changing the signature here will be a problem during the deployment because the old task processor instances will not be able to execute the function with the updated arguments. We need to resolve this please in a new PR.

I suggest that we just add a new argument changed_by to the task function and update the calling code to only send changed_by_user_id if request.user is an FFAdminUser and then ignore that field in the actual task handler.

Note: we should probably consider adding some kind of versioning logic to the task processor to handle this in the future too.

kwargs = {
"environment_api_key": self.environment_api_key,
"identifier": self.identifier,
"user_id": getattr(user, "id", None),
Copy link
Contributor

Choose a reason for hiding this comment

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

This will start to fail in the future if someone adds the id attribute to the APIKeyUser class. Will a test pick it up if so? Or should we be more explicit with this check? e.g.

"user_id": user.id if not getattr(user, "is_master_api_key_user", False) else None

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.

AttributeError: 'APIKeyUser' object has no attribute 'id'
4 participants