[Django] #28313: Model name length is not enforced or validated

11 views
Skip to first unread message

Django

unread,
Jun 15, 2017, 8:21:02 AM6/15/17
to django-...@googlegroups.com
#28313: Model name length is not enforced or validated
-------------------------------------+-------------------------------------
Reporter: Michal | Owner: nobody
Dabski |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 1.8
contrib.contenttypes | Keywords: contenttype, model,
Severity: Normal | name, length, migration
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When creating a model with name longer than 100 characters, {{{migrate}}}
will fail with the following trace:
{{{
Traceback (most recent call last):
File "C:/Users/Mick/Desktop/Projects/django/meg-forms/manage.py", line
14, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\__init__.py", line 363, in
execute_from_command_line
utility.execute()
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\commands\migrate.py", line 227, in handle
self.verbosity, self.interactive, connection.alias,
apps=post_migrate_apps, plan=plan,
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\core\management\sql.py", line 53, in
emit_post_migrate_signal
**kwargs
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\dispatch\dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\contrib\auth\management\__init__.py", line 63, in
create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\contrib\contenttypes\models.py", line 60, in get_for_model
model=opts.model_name,
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\query.py", line 466, in get_or_create
return self._create_object_from_params(lookup, params)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\query.py", line 498, in
_create_object_from_params
obj = self.create(**params)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\query.py", line 394, in create
obj.save(force_insert=True, using=self.db)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\base.py", line 806, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\base.py", line 836, in save_base
updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\base.py", line 922, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk,
raw)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\base.py", line 961, in _do_insert
using=using, raw=raw)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\query.py", line 1063, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\models\sql\compiler.py", line 1099, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\backends\utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\backends\utils.py", line 66, in execute
return self.cursor.execute(sql, params)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\Mick\Desktop\Projects\django\meg-forms\lib\site-
packages\django\db\backends\utils.py", line 66, in execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(100)
}}}

saving {{{sqlmigrate}}} to a file and executing it will work fine, which
makes it harder to determine what the issue is - the schema migration does
not have any inserts.
I found that the issue was caused by model name length not fitting into
ContentType's 100 character limit.

I suggest any of the following
# Validate model names in ContentType model and raise a validation error
so it's more clear to the user what is causing it
# Enforce model name length limit
# Truncate model name in ContentType objects down to 100 characters

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

Django

unread,
Jun 15, 2017, 8:21:41 AM6/15/17
to django-...@googlegroups.com
#28313: Model name length is not enforced or validated
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: | Version: 1.8
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage:
name, length, migration | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Michal Dabski:

Old description:

New description:

* Validate model names in ContentType model and raise a validation error


so it's more clear to the user what is causing it

* Enforce model name length limit
* Truncate model name in ContentType objects down to 100 characters

--

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

Django

unread,
Jun 15, 2017, 8:32:11 AM6/15/17
to django-...@googlegroups.com
#28313: Model name length is not enforced or validated
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: | Version: 1.11

contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage:
name, length, migration | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Michal Dabski):

* version: 1.8 => 1.11


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

Django

unread,
Jun 15, 2017, 9:34:44 AM6/15/17
to django-...@googlegroups.com
#28313: Model name length is not enforced or validated
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted


Comment:

I guess we could add a `django.contrib.contenttypes` system check for
that.

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:3>

Django

unread,
Jun 15, 2017, 9:44:49 AM6/15/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters

-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:4>

Django

unread,
Jun 15, 2017, 4:30:28 PM6/15/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned

Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Michal Dabski):

* owner: nobody => Michal Dabski
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:5>

Django

unread,
Jun 15, 2017, 5:52:45 PM6/15/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michal Dabski):

Merge request:
https://github.com/django/django/pull/8647

Is a test case needed?
Can this be backported to LTS?

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:6>

Django

unread,
Jun 15, 2017, 9:21:56 PM6/15/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* has_patch: 0 => 1
* needs_tests: 0 => 1


Comment:

Yes, tests are always required unless it's infeasible.

This does not qualify for a backport based on our
[https://docs.djangoproject.com/en/dev/internals/release-process
/#supported-versions supported versions policy]. I don't think model names
longer than 100 characters are common.

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:7>

Django

unread,
Jun 16, 2017, 4:44:23 PM6/16/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michal Dabski):

I added tests and pushed to my branch, but the pull request did not update
for me... should I open a new one or is this some temporary hiccup on
github?

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:8>

Django

unread,
Jun 18, 2017, 9:46:49 AM6/18/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tom):

The merge request appears to have tests, except the
``test_model_name_too_long`` test seems to fail.

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:9>

Django

unread,
Jun 18, 2017, 9:49:42 AM6/18/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michal Dabski):

I noticed the mr got update do the next day. I'll fix the test. I didn't
know it was failing since I couldn't get the test suite to run on my pc

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:10>

Django

unread,
Jun 19, 2017, 3:53:07 PM6/19/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Michal Dabski):

Should be ready now; tests added, documentation updated. Any more
feedback?

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:11>

Django

unread,
Jun 19, 2017, 4:04:01 PM6/19/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Michal
Type: | Dabski
Cleanup/optimization | Status: assigned
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Michal Dabski):

* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:12>

Django

unread,
Jun 26, 2017, 5:30:59 PM6/26/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: (none)
Type: | Status: new
Cleanup/optimization |

Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Michal Dabski):

* owner: Michal Dabski => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:13>

Django

unread,
Jun 26, 2017, 6:31:18 PM6/26/17
to django-...@googlegroups.com
#28313: Add a contenttypes check to prohibit model names greater than 100
characters
-------------------------------------+-------------------------------------
Reporter: Michal Dabski | Owner: Tim
Type: | Graham <timograham@…>
Cleanup/optimization | Status: closed
Component: | Version: 1.11
contrib.contenttypes |
Severity: Normal | Resolution: fixed

Keywords: contenttype, model, | Triage Stage: Accepted
name, length, migration |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: (none) => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"d381914aef50e04ca44b9d7bb9274c8351f5b9bf" d381914]:
{{{
#!CommitTicketReference repository=""
revision="d381914aef50e04ca44b9d7bb9274c8351f5b9bf"
Fixed #28313 -- Added model name max length check of 100 characters in
contrib.contentttypes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28313#comment:14>

Reply all
Reply to author
Forward
0 new messages