#30564: Cannot create custom field that returns a queryset AND uses pre_save().
-------------------------------------+-------------------------------------
     Reporter:  Dan J Strohl         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     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 felixxm):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 > 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.

 Your custom field implementation is quite complicated. Custom fields with
 `pre_save()` works properly because you can treat any Django's field as a
 custom field e.g. `DateField`. It seems (but it is hard to tell without
 `pre_save_func()`) that in your case `pre_save()` returns `Query` which is
 not expected by `SQLInsertCompiler.prepare_value()`, that's why IMO it is
 an issue in your implementation/approach.

 > Since these are all normal Django objects.

 You cannot assume that Django internals will handle everything, even if
 these objects are defined by Django.

 I think that `return self.get_db_prep_value(value)` in `pre_save()` in
 branch with `pre_save_func()` should fix your issue.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30564#comment:5>
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.70da6bf7f642a2f576a11e5a07c225f0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to