#19777: Casting a SimpleLazyObject to an int fails -------------------------------------+------------------------------------- Reporter: mattrobenolt | Owner: nobody Type: Bug | Status: closed Component: Core (Other) | Version: master Severity: Normal | Resolution: wontfix Keywords: functional | Triage Stage: simplelazyobject | Unreviewed Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by jacob):
* status: new => closed * needs_better_patch: => 0 * resolution: => wontfix * needs_tests: => 0 * needs_docs: => 0 Comment: Closing after IRC discussion: {{{ jacobkm: mattrobenolt: I'm a bit confused: why are you passing a user into something that expects an int? jacobkm: I don't think it really has anything to do with the lazy object; if you did that with a non-lazy object you'd just get something like " int() argument must be a string or a number, not 'User'" mattrobenolt: jacobkm: So we've been staring at this. mattrobenolt: There's a bug in our code which causes us to pass in an AnonymousUser to our filter. mattrobenolt: Which uncovered the SimpleLazyObject bug. mattrobenolt: Inside Django's RelatedField._pk_trace, it's looking for a model's pk to get around the coersion. mattrobenolt: If it's an Anonymous user, there is none of that, so it fails ugly. mattrobenolt: So I guess we've uncovered a couple issues. 1) A bug in our code. mattrobenolt: 2) A bug in coercing any SimpleLazyObject to an int with __int__. mattrobenolt: 3) Should passing an AnonymousUser to a filter yield a better error? jacobkm: I'd say no to 3 since that would basically require special-casing AnonymousUser somewhere nasty. mattrobenolt: I agree on that. jacobkm: I'm trying to think through why you'd need __int__ on the lazy object. It's not really a public API, it's just used within Django in a few places, and we never need it in an int context. jacobkm: So I'm inclined to say "no" mattrobenolt: Yeah, after uncovering our bug, it wouldn't have solved it since it's still a bug on our end. mattrobenolt: Err, that didn't make much sense, but yeah. mattrobenolt: I'm trying to think of a better way to solve this. At least in terms of a better error message. mattrobenolt: Because this was terrible to track down considering we pinned it on that. :) fhahn left the chat room. (Ping timeout: 248 seconds) jacobkm: Yeah I think I'm gonna close this; if you come up with a way to make better error messages I'm all about that. }}} -- Ticket URL: <https://code.djangoproject.com/ticket/19777#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.