-
-
Notifications
You must be signed in to change notification settings - Fork 7k
permissions must return a boolean to allow &/| operator comparison #6286
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
Conversation
`x and y` actually returns object y when both are true. the means P & IsAuthenticated will fail with TypeError: unsupported operand type(s) for &: 'instance' and 'bool' as IsAuthenticated now returns a CallableBool which does not overload __ror__
Hi, This is too abstract without a test case to demonstrate the issue. |
@xordoquy I explained the case in the description but here is an explicit test case:
The last line raises: The reason this occurs is explained in my original description. |
Updated test cases to reflect the change in django. Is there a way to use a real django user object instead of FakeUser? I believe that wouldve caught this case. |
@markddavidoff if fact, you don't want a user if you want the test to fail.
and it wouldn't fail until I correct that part with:
in which case it would now fail. |
@xordoquy what version of django are you using when you run the test. CallableBool is in Django versions: Django 1.10.0-Django 2.1.2. I don't understand your last comment at all. The issue is with is_authenticated returning an object not a bool. Steps for you to repro this:
|
@xordoquy I have added this pr: #6287 to show you the issue, with just the test change. look at the output to the django 1.11 output |
OK, I get it.
This being said, you demonstrated an issue when there's no user to a request (whatever reason there might be). So I'll be willing to fix it though not spending too much time on the |
if this helped you discover another issue that's great, but the issue I
described is also a problem and I would like to address that in this pr
…On Mon, Oct 29, 2018, 9:15 AM Xavier Ordoquy ***@***.*** wrote:
OK, I get it.
CallableBool is only available for Django 1.11 as it's on the path of the
is_authenticated migration from a function to a property.
The Django 2.0 release notes state:
Using User.is_authenticated() and User.is_anonymous() as methods rather
than properties is no longer supported.
This being said, you demonstrated an issue when there's no user to a
request (whatever reason there might be). So I'll be willing to fix it
though not spending too much time on the CallableBool as the next minor
will drop support for Django 1.11 anyway.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6286 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABTCn1vA_HxWXqdKpKMr6EIk11nSZ9CEks5upym1gaJpZM4X-L-l>
.
|
Sure thing, but you'll need to find a workaround for the test to pass for Django 2.0+ |
Fixed test |
@xordoquy updated test |
Thanks for the PR, nice work. |
x and y
actually returns object y when both are true. This meansSomePermission & IsAuthenticated
will fail withTypeError: unsupported operand type(s) for &: 'instance' and 'bool'
asIsAuthenticated
now returns aCallableBool
which does not overload__ror__
(at least in Django==1.11.16)An alternative approach is explicitly calling
bool()
inAND
andOR
, which would allowhas_permission
to return truthy non boolean objects, but i feel permissions should be more explicit than that. If this approach makes sense I can add tests.Note: Before submitting this pull request, please review our contributing guidelines.
Description
Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use
refs #...
in the description of the pull request.