Opened 11 years ago

Closed 11 years ago

#9864 closed (fixed)

Error message regarding mysql version is never used in the code added by r9650

Reported by: ElliottM Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In django.db.backends.mysql.validation, there is the following code to handle validation of varchar fields:

19 	            if db_version < (5, 0, 3):
20 	                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %(version)s).'
21 	            if f.unique == True:
22 	                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
23 	            else:
24 	                msg = None

If you look carefully, the mysql version ends up being irrelevant. The cause is the "else" on line 23. The "if" it matches to only tests for unique=True, so if unique is false then msg will be None, even if the user has an incompatible mysql version.

To solve it, I removed the else, put "msg=None" above the two if ststements, then switched the two if statements. The reason for the switch is that if the user both has a unique field and has an incompatible version, we want to display the incompatible version error message.

Attachments (1)

version-error-msg.diff (1.1 KB) - added by ElliottM 11 years ago.

Download all attachments as: .zip

Change History (2)

Changed 11 years ago by ElliottM

Attachment: version-error-msg.diff added

comment:1 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Nice catch. I also spotted this last night and made a shorter fix with the same intent. Just remembered to commit it, so fixed in r9659 (and r9660 on 1.0.X).

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