[Django] #29831: Add validation on the `--name` argument in makemigrations

12 views
Skip to first unread message

Django

unread,
Oct 8, 2018, 5:42:59 AM10/8/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime | Owner: nobody
Lorant |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 2.1
Migrations | Keywords: migrations name
Severity: Normal | makemigrations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
After creating a new empty migration, I got an error when applying it. The
error is pretty clear when you have the context but can be misleading for
beginners: I created a migration containing a dot in its name so Django
has split the migration and fails to import the module somehow.

{{{
$ python manage.py makemigrations myapp --empty -n "remove_foo.bar_thing"
Migrations for 'myapp':
myproject/myapp/migrations/0085_remove_foo.bar_thing.py
^ notice the dot here


$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 6, in <module>
execute_from_command_line(sys.argv)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/core/management/__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/core/management/commands/migrate.py", line 79, in handle
executor = MigrationExecutor(connection,
self.migration_progress_callback)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 201, in build_graph
self.load_disk()
File "/data/.virtualenvs/MY_VENV/lib/python3.5/site-
packages/django/db/migrations/loader.py", line 110, in load_disk
migration_module = import_module("%s.%s" % (module_name,
migration_name))
File "/data/.virtualenvs/MY_VENV/lib/python3.5/importlib/__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in
_call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in
_find_and_load_unlocked
ImportError: No module named 'myproject.myapp.migrations.0085_remove_foo'
}}}

I suggest to add a validation step that fails when the migration name
supplied with the `-n/--name` argument contains dots (and why not spaces
too?).

To be honest, I only tried this on Django 2.0.x, but I did not see any
changes about this problem in Django 2.1 releases notes.

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

Django

unread,
Oct 9, 2018, 6:35:12 AM10/9/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner: nixphix
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage:
makemigrations | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* owner: nobody => nixphix
* status: new => assigned


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

Django

unread,
Oct 9, 2018, 8:39:03 PM10/9/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner: nixphix
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


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

Django

unread,
Oct 10, 2018, 8:48:10 AM10/10/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner: nixphix
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Herbert Fortes):

* cc: Herbert Fortes (added)


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

Django

unread,
Oct 12, 2018, 1:12:22 PM10/12/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner:
Type: | Prabakaran Kumaresshan
Cleanup/optimization | Status: assigned

Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 0 | Needs documentation: 0

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

Comment (by Herbert Fortes):

Replying to [comment:1 Prabakaran Kumaresshan]:

Hi,

How are things going?

My first thought is to edit
[https://github.com/django/django/blob/master/django/core/management/commands/makemigrations.py#L63
makemigrations] and
[https://github.com/django/django/blob/8ef8bc0f64c463684268a7c55f3d3da4de066c0d/tests/migrations/test_commands.py#L1323
test_commands]

I am not pushing. Not at all. I am just talking about the ticket. Feel
free.

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

Django

unread,
Oct 13, 2018, 1:53:12 AM10/13/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner:
Type: | Prabakaran Kumaresshan
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 0 | Needs documentation: 0

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

Comment (by Prabakaran Kumaresshan):

Replying to [comment:4 Herbert Fortes]:


> Replying to [comment:1 Prabakaran Kumaresshan]:
>
> Hi,
>
> How are things going?
>
> My first thought is to edit
[https://github.com/django/django/blob/master/django/core/management/commands/makemigrations.py#L63
makemigrations] and
[https://github.com/django/django/blob/8ef8bc0f64c463684268a7c55f3d3da4de066c0d/tests/migrations/test_commands.py#L1323
test_commands]
>
> I am not pushing. Not at all. I am just talking about the ticket. Feel
free.

Hi,

This is my first contribution. I figured the code that needs patch just
wondering where to place test scripts, thanks for the link.
I'll do regression and apply patch then let you know.

Much appreciate your help

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

Django

unread,
Oct 19, 2018, 10:41:15 AM10/19/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner:
Type: | Prabakaran Kumaresshan
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Prabakaran Kumaresshan):

* has_patch: 0 => 1


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

Django

unread,
Oct 23, 2018, 10:27:28 AM10/23/18
to django-...@googlegroups.com
#29831: Add validation on the `--name` argument in makemigrations
-------------------------------------+-------------------------------------
Reporter: Maxime Lorant | Owner:
Type: | Prabakaran Kumaresshan
Cleanup/optimization | Status: closed
Component: Migrations | Version: 2.1
Severity: Normal | Resolution: fixed

Keywords: migrations name | Triage Stage: Accepted
makemigrations |
Has patch: 1 | Needs documentation: 0

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

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"10d82c85aa5f8bd6adff0db49798dd368455cdcf" 10d82c8]:
{{{
#!CommitTicketReference repository=""
revision="10d82c85aa5f8bd6adff0db49798dd368455cdcf"
Fixed #29831 -- Added validation for makemigrations --name.
}}}

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

Reply all
Reply to author
Forward
0 new messages