Code

Opened 6 years ago

Closed 6 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: UI/UX:

Description

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 6 years ago.

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by ElliottM

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.