-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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(issue-views): Update endpoints to send and receive page filters #83937
base: master
Are you sure you want to change the base?
feat(issue-views): Update endpoints to send and receive page filters #83937
Conversation
gsv = GroupSearchView.objects.get(id=view["id"], user_id=user_id) | ||
gsv.name = view["name"] | ||
gsv.query = view["query"] | ||
gsv.query_sort = view["querySort"] | ||
gsv.position = position | ||
gsv.is_all_projects = view.get("isAllProjects", False) | ||
|
||
if "projects" in view: | ||
gsv.projects.set(view["projects"]) | ||
|
||
if "environments" in view: | ||
gsv.environments = view["environments"] | ||
|
||
if "timeFilters" in view: | ||
gsv.time_filters = view["timeFilters"] | ||
|
||
gsv.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't set projects directly in the .update()
since it's an M2M, so we have to do this shenanigans
6abadbe
to
de738a2
Compare
❌ 1 Tests Failed:
View the top 1 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
de738a2
to
c6e4f22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaelSun48 do you think there is value in feature flagging any of this logic? I'm just a bit worried about adding so much code that we can't easily roll back
try: | ||
validate_projects(organization, request.user, view) | ||
except ValidationError as e: | ||
sentry_sdk.capture_message(e.args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we wouldn't want to capture the error since this is expected. Did you add this just to be certain nothing is wrong during rollout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's right, the frontend should never be sending invalid projects anyways, so capturing this is mostly just to verify that.
def validate_projects( | ||
org: Organization, user: User | AnonymousUser, view: GroupSearchViewValidatorResponse | ||
) -> None: | ||
if "projects" in view and view["projects"] is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there are quite a few if statements here. IMO it's more readable if you add early returns instead, but this is just a style preference so feel free to ignore
view["isAllProjects"] = True | ||
view["projects"] = [] | ||
else: | ||
projects = Project.objects.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit slow if you have many views since it does each in sequence. Do you think it's necessary to check this? The db transaction should fail if the project ID doesn't exist right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't consider that, great point! Yeah this definitely would have added a lot of unnecessary database queries
@malwilley Yeah I think I was initially adverse because it seemed pretty complicated ot split some of the serializer logic, but looking at this again, I don't think it should be too bad. I'll add that in in the next PR, good suggestion! fwiw, I think these changes should be pretty safe, assuming I correctly wrote it in a way that doesn't interfere with how the frontend works right now. |
@MichaelSun48 no need to split if the changes are indeed trivial. I'd just make sure to run this locally in the UI and make sure that things are working well (for global views permissions on/off) before merging since the unit tests can't catch everything |
response = self.client.put( | ||
url, data={"views": views}, format="json", content_type="application/json" | ||
) | ||
assert response.status_code == 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should respond with a 4xx code since invalid project IDs are a bad request. Anytime I see a 500 I think it's an unexpected error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure if this is possible since this check occurs when the transaction is committed and not when the view is actually updated, so it might be impossible to tell what caused the integrity violation (though I will dig deeper into this)
We could query the Projects table again and check, for each view, if it's projects exist in the QuerySet, but then the only purpose of that data query would be to make the error message more accurate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not worth making the extra request, but I hope there is a way to discern the type of violation because I'm sure we'll get some Sentry issues at some point and will want to know if it's expected behavior or not
@@ -129,6 +157,20 @@ def bulk_update_views( | |||
_update_existing_view(org, user_id, view, position=idx) | |||
|
|||
|
|||
def pick_default_project(org: Organization, user: User | AnonymousUser) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anymore right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! But it will eventually be used for the get endpoint 😅
This PR updates the two Groupsearch view endpoints:
PUT ../group-search-view
: updated to optionally accept the four new page filter parameters. The frontend will be updated shortly to send over these parameters.GET ../group-search-view
: updated to return the four new page filter parameters. The frontend will not do anything with these parameters until later.