#22683 closed Cleanup/optimization (wontfix)

Schema tests and .extra queryset method

Reported by: maxi Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by shai)

Running schema tests I caught an issue, more precisely, in test_add_field_default_transform.
At the end, this test method is doing:

self.assertEqual(Author.objects.extra(where=["thing = 1"]).count(), 2)

The problem here is what in this where clause, the "thing" field must be quoted.

In firebird :

    SELECT * FROM AUTHOR WHERE thing = 1   -- Here thing (in lowercase) and THING (in uppercase) are equivalent, are the same object

is different of:

    SELECT * FROM AUTHOR WHERE "thing" = 1   --  field is quoted

For a more generic test I think we need to avoid use .extra method or another raw sql statement.

For a more complete discussion about it, see at

Change History (2)

comment:1 Changed 17 months ago by shai

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization
  • Version changed from 1.6 to 1.7-beta-2

Added some formatting to description.

We should be able to get rid of the raw sql there, since the model has the added column.

comment:2 Changed 13 months ago by andrewgodwin

  • Resolution set to wontfix
  • Status changed from new to closed

Unfortunately, we can't use the model there - it doesn't have the added column (we can't mutate the models in the schema tests as they're used for multiple tests - the test just runs add_field on it, there's nothing in there that actually adds it to the model and runs contribute_to_class).

Given the fragility of moving this to add itself and then undo the damage shortly after, and the fact that this test is passing just fine on all backends AFAIK (unquoted names are valid SQL, and I'm not aware of any DBs with 'thing' as a keyword), I'm going to close this as WONTFIX. Someone should reopen if a database is discovered where this breaks.

Note: See TracTickets for help on using tickets.
Back to Top