#30564: Cannot create custom field that returns a queryset AND uses pre_save(). -------------------------------------+------------------------------------- Reporter: Dan J Strohl | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Dan J Strohl):
* status: closed => new * resolution: invalid => Comment: Re-opening this, I think you mis-understood my point. I understand that there are other approaches I can take, and I am looking at them (and am happy for the suggestions). however, the issue as I reported it actually IS with Django. The issue is that by using ```if hasattr(value, 'resolve_expression')```, you cannot deterministically tell the difference between a SQL expression and a Django QuerySet. perhaps there is a way around this that I haven't seen, in which case, I apologize for missing it. however by following the docs, when I return a QuerySet object, and when a pre_save method is used, the system raises an error since the QuerySet object matches your check, but is not an expression object. (or, if you ARE considering it an expression object for some reason, then the bug is that it does not have all of the OTHER required methods that the expected one does.). I understand that using ```if hasattr``` is the preferred approach, and I am not saying that the only fix is to change that, you could so a second check after it, change the method name in the queryset, have an alternative path that doesn't check for the method... etc... (all of which seem like much more work than changing the "if" check), but there may be other issues that I don't see (I haven't looked deeply enough at the code to see what other issues that would cause). I don't know the flow or code well enough to say either way. I simply brought it up as a potential approach. Either way though, the bug I am reporting is that when returning a django queryset, via a custom field with a pre_save, it raises an AttributeError. Since these are all normal Django objects, and I'm using documented django approaches, I see this as a bug. If the returned object was something I controlled, I would simply re-name the "resolve_expression" method so it didn't' get caught, but I can't (easily) do that for a django QuerySet. I won't argue this again if you want to close this again, I'm not trying to get into a war here or anything. I think it's pretty much a corner case, but I do see it as a bug and wanted to make sure I was at least being clear. -- Ticket URL: <https://code.djangoproject.com/ticket/30564#comment:3> 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. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.28ecb6df664bafddd923c2355744883d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.