#25493: Model instances created with unittest.mock can raise confusing errors
-------------------------------------+-------------------------------------
Reporter: jarshwah | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.9a1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django can raise one of the following
- `ValueError: Failed to insert expression` or;
- `ValueError: Failed to insert expression "<MagicMock
name='create().id.resolve_expression()' id='139633074508184'>" on
fundraising.Payment.stripe_charge_id. F() expressions can only be used to
update, not to insert.`
when using unittest.mock to mock the creation of an object. The
djangoproject.com tests began throwing errors. Tim fixed these problems in
this PR: https://github.com/django/djangoproject.com/pull/524
The PR adds return values for the id of columns that are used to create
new instances to avoid these errors.
What I think is happening is that the lack of id is somehow causing the
mock to be treated as a `Col`. The existence of a `Col` in a
`objects.create()` call is what triggers the confusing error message.
Since no `F()` expression has been used by the user, tracking down the
cause is difficult.
We should try and figure out why the mock is being resolved to a Col and
stop that from happening or improve the error message if that's not
possible.
--
Ticket URL: <https://code.djangoproject.com/ticket/25493>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.9b03b50c67c02018c2b5d01342b55eaf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.