﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25493	Model instances created with unittest.mock can raise confusing errors	Josh Smeaton	Marcelo Galigniana	"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."	Cleanup/optimization	closed	Database layer (models, ORM)	1.9	Normal	wontfix		josh.smeaton@…	Accepted	0	0	0	0	0	0
