#30371: sqlmigrate fails with string defaults on mysql
-------------------------------------+-------------------------------------
Reporter: Melvyn Sopacua | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Release blocker | Resolution: needsinfo
Keywords: regression | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Melvyn Sopacua):
I think the proper fix here is to confirm both str on value and 'decode'
attribute on quoted.
I've tried to add a test for it, but the code never gets called anymore in
the scope of migrations, because Django no longer transmits default values
to the backend. So the issue is with [https://github.com/3YOURMIND/django-
add-default-value our extension] that ensures we can do blue/green
deployments. Looking at
[https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/converters.py this
code] confirms your suspicions that pymysql returns strings.
Still - when I read the code the first few times until you highlighted the
fact here, I thought the if clause and the modification are using the same
value, cause it's such a common pattern you don't read the variable name
anymore.
And secondly, it assumes that quoted has the decode() method based on a
not related test, so I still suggest to fix it like this:
{{{
if isinstance(value, str) and callable(getattr(quoted, 'decode', None)):
quoted = quoted.decode()
}}}
This doesn't require the performance hit of force_text and it even
supports exotic quoted values that implement a decode() method.
--
Ticket URL: <https://code.djangoproject.com/ticket/30371#comment:8>
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/064.ae0a97001aeb0c233082d4d2db124f2f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.