http://dev.mysql.com/doc/refman/5.6/en/server-system-
variables.html#sysvar_sql_auto_is_null
System Variable Name sql_auto_is_null
Variable Scope Global, Session
Dynamic Variable Yes
Permitted Values Type boolean
Default 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24675>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => ssjunior
* status: new => assigned
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:1>
* status: assigned => closed
* resolution: => fixed
Comment:
Pull request submitted.
https://github.com/django/django/pull/4538
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:2>
* status: closed => new
* resolution: fixed =>
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:3>
Comment (by timgraham):
Can we avoid the setting and make it a function of the MySQL version? I'm
not clear if it's always safe to skip this query on MySQL 5.6+, or only
when also setting a MySQL server variable?
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:4>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:5>
Comment (by ssjunior):
I think that I have a better solution. Check in the features for the
status on the server and issue the command only if it is True on the
server. Tell me what do you think and if it is ok I will submitt a new PR.
https://github.com/ssjunior/django/commit/52bf6c7630ab6b17a3a3ff64213e1ad36d6fe270
{{{
@cached_property
def sql_auto_is_null(self):
"Return if server global variable sql_auto_is_null is set to True"
with self.connection.cursor() as cursor:
cursor.execute("SHOW GLOBAL VARIABLES LIKE
'sql_auto_is_null'")
return cursor.fetchone()[1] == 'ON'
def init_connection_state(self):
# SQL_AUTO_IS_NULL in MySQL controls whether an AUTO_INCREMENT
column
# on a recently-inserted row will return when the field is tested
for
# NULL. Disabling this value brings this aspect of MySQL in line
with
# SQL standards.
# Check the sql_auto_is_null status on the MySQL server and if
necessary
# set it to False.
if self.features.sql_auto_is_null:
with self.cursor() as cursor:
cursor.execute('SET SQL_AUTO_IS_NULL = 0')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:6>
Comment (by claudep):
Looks good, please make it a pull request. It will need some tests,
though.
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:7>
* needs_better_patch: 1 => 0
* needs_tests: 0 => 1
Comment:
Claude, how did you imagine a test would look like for this?
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:8>
Comment (by claudep):
Something like: take a connection object, close it, reopen it and check
that no `SQL_AUTO_IS_NULL` query is done.
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:9>
* status: new => closed
* resolution: => fixed
Comment:
https://github.com/django/django/pull/5794
I made a new pull request for this issue. Added testing as well.
Can you check if it looks good?
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:10>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:11>
* status: closed => new
* resolution: fixed =>
Comment:
We only mark tickets fixed when the PR has been merged.
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:12>
Comment (by stewartpark):
I see! Sorry about that. Any plan on reviewing this pull request?
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:13>
* needs_better_patch: 0 => 1
Comment:
Left some minor comments. Please uncheck "Patch needs improvement" when
you update it, thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:14>
* needs_better_patch: 1 => 0
Comment:
I fixed the code the way you suggested. :) Also passed all the test cases.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:15>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"b7fdd60d85ee94df444369be1b2c778cda44a0c2" b7fdd60]:
{{{
#!CommitTicketReference repository=""
revision="b7fdd60d85ee94df444369be1b2c778cda44a0c2"
Fixed #24675 -- Skipped SQL_AUTO_IS_NULL query on MySQL if not needed.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:16>
Comment (by brianwawok):
In development I still see 2 queries per page load for this. I assume
because connections do not persist in dev.
Seems this needs dealt with in a different way in dev?
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:17>
Comment (by charettes):
This patch has only be merged in the ''master'' branch so far and is not
part of any official release. It should be part of the upcoming 1.10
release.
--
Ticket URL: <https://code.djangoproject.com/ticket/24675#comment:18>