[Django] #22683: Schema tests and .extra queryset method

8 views
Skip to first unread message

Django

unread,
May 22, 2014, 9:51:18 AM5/22/14
to django-...@googlegroups.com
#22683: Schema tests and .extra queryset method
-------------------------------+--------------------
Reporter: maxi | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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
https://groups.google.com/forum/?hl=es#!topic/django-
developers/KRHD77KlZ28

--
Ticket URL: <https://code.djangoproject.com/ticket/22683>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 26, 2014, 8:27:35 PM5/26/14
to django-...@googlegroups.com
#22683: Schema tests and .extra queryset method
-------------------------------------+-------------------------------------
Reporter: maxi | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version:
Component: Migrations | 1.7-beta-2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by shai):

* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.6 => 1.7-beta-2
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Old description:

> 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
> https://groups.google.com/forum/?hl=es#!topic/django-
> developers/KRHD77KlZ28

New description:

Running schema tests I caught an issue, more precisely, in

`test_add_field_default_transform`.


At the end, this test method is doing:

{{{#!python


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 :
{{{#!sql


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

{{{#!sql


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
https://groups.google.com/forum/?hl=es#!topic/django-
developers/KRHD77KlZ28

--

Comment:

Added some formatting to description.

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

--
Ticket URL: <https://code.djangoproject.com/ticket/22683#comment:1>

Django

unread,
Sep 5, 2014, 3:13:50 PM9/5/14
to django-...@googlegroups.com
#22683: Schema tests and .extra queryset method
-------------------------------------+-------------------------------------
Reporter: maxi | Owner: nobody
Type: | Status: closed

Cleanup/optimization | Version:
Component: Migrations | 1.7-beta-2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by andrewgodwin):

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


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/22683#comment:2>

Reply all
Reply to author
Forward
0 new messages