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(tags/view): Add api to get tag by uuid #3229

Merged
merged 3 commits into from
Jan 9, 2024
Merged

Conversation

gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Jan 3, 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

Add API to fetch tag by uuid - (will be) Used by our terraform provider to import tag

How did you test this code?

Adds unit test

Copy link

vercel bot commented Jan 3, 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 Jan 5, 2024 3:43am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 5, 2024 3:43am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 5, 2024 3:43am

@codecov-commenter
Copy link

codecov-commenter commented Jan 3, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (93ea01c) 95.95% compared to head (b1c8108) 76.25%.
Report is 8 commits behind head on main.

Files Patch % Lines
api/projects/tags/views.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3229       +/-   ##
===========================================
- Coverage   95.95%   76.25%   -19.71%     
===========================================
  Files        1062     1035       -27     
  Lines       32299    31345      -954     
===========================================
- Hits        30993    23901     -7092     
- Misses       1306     7444     +6138     

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

Copy link
Contributor

github-actions bot commented Jan 3, 2024

Uffizzi Preview deployment-43732 was deleted.

@gagantrivedi gagantrivedi requested review from a team and zachaysan and removed request for a team January 3, 2024 05:32
serializer.save(project_id=project_id)

def perform_update(self, serializer):
project_id = self.kwargs["project_pk"]
project_id = int(self.kwargs["project_pk"])
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 done to make sure the response have correct data type for project(i.e: int instead of string)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the serializer with is_valid?

Copy link
Member Author

@gagantrivedi gagantrivedi Jan 4, 2024

Choose a reason for hiding this comment

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

Sorry, I don't understand how that will help change the data type of the response?

Copy link
Contributor

Choose a reason for hiding this comment

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

Getting the data type with validated_data after running the is_valid check should remove the requirement for the int cast, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that does not work, I don't think any data passed to save() is part of validated data 🤔 unless I am doing something wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we're talking past each other, and this is a minor thing so I'll approve the PR just to unblock you, but typically when I use serializers I'm able to call is_valid on the serializer then pass validated_data into whatever I need. This works for all sorts of situations including stuff like query params serializers. If the kwargs can be passed into the serializer and the serializer can validate the data then why do it manually with type casts?

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 think the part that you are talking about is handled by drf(update method in this case) and I honestly don't see much value in overriding the update method

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 will merge this for now, but let me know if disagree

Comment on lines +11 to +14
@pytest.mark.parametrize(
"client",
[(lazy_fixture("admin_master_api_key_client")), (lazy_fixture("admin_client"))],
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We're prioritizing using lower levels of access over the admin_client when it comes to checking permissions. So since this endpoint follows TagPermissions you'll want to use staff_client with the with_project_permissions([VIEW_PROJECT]) to set access level to match.

Also, it would be good to check the HTTP 403 case to make sure the endpoint isn't open to a user from a different project.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point… Although I wonder if that should be done by the unit test that test the permission class itself instead of the test that test the view?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since permissions can be misconfigured when adding to a viewset (which we've found wide open ones because of a decorator misordering) I think testing through the view overall is a better strategy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that makes sense

serializer.save(project_id=project_id)

def perform_update(self, serializer):
project_id = self.kwargs["project_pk"]
project_id = int(self.kwargs["project_pk"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we're talking past each other, and this is a minor thing so I'll approve the PR just to unblock you, but typically when I use serializers I'm able to call is_valid on the serializer then pass validated_data into whatever I need. This works for all sorts of situations including stuff like query params serializers. If the kwargs can be passed into the serializer and the serializer can validate the data then why do it manually with type casts?

@gagantrivedi gagantrivedi added this pull request to the merge queue Jan 9, 2024
Merged via the queue into main with commit 6500451 Jan 9, 2024
@gagantrivedi gagantrivedi deleted the feat/get-tags-by-uuid branch January 9, 2024 09:03
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