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

Allow DjangoObjectPermissions to use views that define get_queryset#2905

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

Merged

Conversation

@ticosax
Copy link
Contributor

I'm sorry for the noise. I hope this time it is the right one.

It is a refactoring of#2904, I added explicit support forAPIRoot with a test.

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 probably prefer for us to just leave the logic in the method itself.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fair enough

@ticosaxticosaxforce-pushed thedjango-object-perm-get_queryset branch from63c84c3 toea2bc91CompareMay 5, 2015 13:05
@ticosax
Copy link
ContributorAuthor

@tomchristie I addressed your comment.
Let me know if you see something else.

@ticosaxticosaxforce-pushed thedjango-object-perm-get_queryset branch fromea2bc91 tofbd8156CompareMay 5, 2015 13:21
@ticosax
Copy link
ContributorAuthor

@xordoquy Is there is a chance to have it included in 3.1.2 ?

@xordoquy
Copy link
Contributor

Will try to find some time to review it before the release

@ticosax
Copy link
ContributorAuthor

Thank you I appreciate.
Because without it, I won't be able to upgrade.

Copy link
Contributor

Choose a reason for hiding this comment

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

This block looks confusing as it currently stands.

Can't it just be...

try:    queryset = view.get_queryset()except AttributeError:    queryset = getattr(view, 'queryset', None)

Or am I missing something?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The problem is that yo can have.get_queryset() defined but its implementation might raiseAttributeError during execution. We should prevent catching thisAttributeError.

Copy link
Contributor

Choose a reason for hiding this comment

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

but its implementation might raise AttributeError during execution.

That's such a crazy edge case that I don't really care about it. I'd prefer clarity of this code, and we'd still be using sensible enough behavior in that case. (Plus we'd expect the error to be raised elsewhere such as when initially using the queryset in the view)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I understand. I'm going to make the change

@lovelydinosaur
Copy link
Contributor

@ticosax@xordoquy Reviewed.

@lovelydinosaur
Copy link
Contributor

I'll put a 3.1.2 label on it speculatively just to keep it surfaced for the moment, but up to@xordoquy if it stays or not.

@lovelydinosaurlovelydinosaur added this to the3.1.2 Release milestoneMay 13, 2015
@ticosaxticosaxforce-pushed thedjango-object-perm-get_queryset branch fromfbd8156 toeb2be3aCompareMay 13, 2015 11:52
@ticosax
Copy link
ContributorAuthor

I made the changes.

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 not sure why we have anAssertionError block here, but it looks wrong. Just the first four lines are sufficient:

try:    queryset = view.get_queryset()except AttributeError:    queryset = getattr(view, 'queryset', None)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Mainly for two reasons:
1 - To honourgetattr(view, '_ignore_model_permissions', False) behaviour. Since some views without .queryset are tolerated.
2 - Because the absence of queryset is raised few lines below with an adhoc error message.

assertquerysetisnotNone, ('Cannot apply DjangoModelPermissions on a view that ')

I thought it would be nice to keep it that way, to be consistent withDjangoModelPermissions

Copy link
Contributor

Choose a reason for hiding this comment

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

We def don't need theAssertionError catching in either case, but it might also be nicer to moveif getattr(view, '_ignore_model_permissions', False): return True behavior to instead beabove the queryset check.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Very nice. I like it.

@lovelydinosaur
Copy link
Contributor

@ticosax Looks nearly there.

@ticosaxticosaxforce-pushed thedjango-object-perm-get_queryset branch fromeb2be3a to031ac2aCompareMay 13, 2015 12:26
@ticosax
Copy link
ContributorAuthor

I pushed a new version.

lovelydinosaur added a commit that referenced this pull requestMay 13, 2015
Allow DjangoObjectPermissions to use views that define get_queryset
@lovelydinosaurlovelydinosaur merged commitea1145c intoencode:masterMay 13, 2015
@lovelydinosaur
Copy link
Contributor

@ticosax
Copy link
ContributorAuthor

😅 Thank you

@ticosaxticosax deleted the django-object-perm-get_queryset branchMay 13, 2015 12:48
@xordoquy
Copy link
Contributor

ace !

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

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

3.1.2 Release

Development

Successfully merging this pull request may close these issues.

3 participants

@ticosax@xordoquy@lovelydinosaur

[8]ページ先頭

©2009-2025 Movatter.jp