Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix UpdateModelMixin to work when no queryset is defined is defined on the view#9314

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

browniebroke
Copy link
Member

Description

It seems that the fix from#8043 isn't working in all cases, especially when the users aren't setting thequeryset attribute, or overriding theget_queryset() method, and instead opt to override theget_object method.

Attempt to fix this edge case by delaying the call ofget_queryset, to be only if the instance that was just updated had some prefetched relations.

Fix#9306

Comment on lines -73 to +72
if queryset._prefetch_related_lookups:
if hasattr(instance, '_prefetched_objects_cache'):
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

When onlyget_object is defined, I assume that folks are unlikely to have advanced prefetches in their method (although it's very much possible).

If some things were prefetched, we assume that there is aget_queryset method.

@browniebrokebrowniebrokeforce-pushed thefix-updatemixin-queryset-error branch from80e09d0 to89c79d6CompareMarch 19, 2024 21:57
@auvipyauvipy self-requested a reviewMarch 20, 2024 08:11
Copy link
Contributor

@yuekuiyuekui left a comment

Choose a reason for hiding this comment

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

Yeah this should fix the case that if only get_object() was defined, looks good to me

instance._prefetched_objects_cache = {}
prefetch_related_objects([instance], *queryset._prefetch_related_lookups)
queryset = self.filter_queryset(self.get_queryset())

Choose a reason for hiding this comment

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

This is still expectingget_queryset orqueryset to be defined and will raise an AssertError if it is not, which means it will still not be backwards compatabile with 3.14 correct?

Copy link
Contributor

@yuekuiyuekuiMar 21, 2024
edited
Loading

Choose a reason for hiding this comment

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

How is it possible thatself has '_prefetched_objects_cache' defined without definingqueryset orget_queryset?

browniebroke reacted with thumbs up emoji
Copy link
MemberAuthor

@browniebrokebrowniebrokeMar 21, 2024
edited
Loading

Choose a reason for hiding this comment

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

That's what I meant by my comment earlier, one might do:

classUserRetrieveWithoutQuerySet(generics.RetrieveUpdateAPIView):serializer_class=UserSerializerdefget_object(self):returnUser.objects.prefetch_related('groups').get(pk=self.kwargs['pk'])

In such case, I would argue that it's reasonable to require users to override theget_queryset method... The error message says exactly that. Would probably need to be documented better, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably just an extraif statement ortry catch would solve all these cases.

@auvipy
Copy link
Member

auvipy commentedMar 21, 2024
edited
Loading

should we revert the actual implementation as breaking change? and then come with a better fix? or in this case we can just go with this?#9327

browniebroke reacted with thumbs up emoji

@browniebroke
Copy link
MemberAuthor

Going to close this as it becoming clear that we should revert. I was only trying to help get a stable 3.15.x out, which a revert achieves...

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mrzornmrzornmrzorn left review comments

@yuekuiyuekuiyuekui approved these changes

@auvipyauvipyAwaiting requested review from auvipy

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3.15 not backwards compatible with 3.14 - "View' should either include aqueryset attribute, or override theget_queryset() method."
4 participants
@browniebroke@auvipy@mrzorn@yuekui

[8]ページ先頭

©2009-2025 Movatter.jp