[Django] #31045: Squashing migrations returns "SyntaxError: Invalid token"

9 views
Skip to first unread message

Django

unread,
Nov 29, 2019, 12:02:30 PM11/29/19
to django-...@googlegroups.com
#31045: Squashing migrations returns "SyntaxError: Invalid token"
-------------------------------------+-------------------------------------
Reporter: benmezger | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords: bug, migrations
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Seems that squashing my app migrations is returning the following error
when running `migrate`. As far as I can see,
0060_auto_20190828_0652.update_store_locator_in_cart_page is an invalid
identifier because it starts with a number. Perhaps checking running
`getattr` before to avoid this issue.

I am not sure whether this is a Django issue or some other library
conflict.


{{{
Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/core/management/__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 79, in handle
executor = MigrationExecutor(connection,
self.migration_progress_callback)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/db/migrations/loader.py", line 201, in build_graph
self.load_disk()
File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-
packages/django/db/migrations/loader.py", line 110, in load_disk
migration_module = import_module("%s.%s" % (module_name,
migration_name))
File
"/Users/benmezger/.pyenv/versions/3.6.0/lib/python3.6/importlib/__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in
source_to_code
File "<frozen importlib._bootstrap>", line 205, in
_call_with_frames_removed
File
"/Users/benmezger/workspace/ckl/skyroam_backend/store/migrations/0001_squashed_0071_product_custom_shipping_rate.py",
line 1272
code=store.migrations.0060_auto_20190828_0652.update_store_locator_in_cart_page,
^
SyntaxError: invalid token
}}}


The generated migrations code:
https://gist.github.com/benmezger/7e63f6a9e3b468b1838c67a7bd4a2bc4

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

Django

unread,
Nov 29, 2019, 12:05:37 PM11/29/19
to django-...@googlegroups.com
#31045: Squashing migrations returns "SyntaxError: Invalid token"
-------------------------------------+-------------------------------------
Reporter: benmezger | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:

Keywords: bug, migrations | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

Old description:

New description:

--

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

Django

unread,
Dec 2, 2019, 3:29:09 AM12/2/19
to django-...@googlegroups.com
#31045: Squashing migrations returns "SyntaxError: Invalid token".
-----------------------------------+--------------------------------------
Reporter: Ben Mezger (seds) | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 2.0
Severity: Normal | Resolution: invalid
Keywords: bug, migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => invalid
* component: Database layer (models, ORM) => Migrations


Comment:

I think you missed a comment at the begging of a squashed migration (see
#22983):
{{{
# Functions from the following migrations need manual copying.
# Move them and any dependencies into this file, then update the
# RunPython operations to refer to the local versions:
# store.migrations.0060_auto_20190828_0652
}}}

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

Reply all
Reply to author
Forward
0 new messages