Opened 3 years ago

Closed 3 years ago

#27436 closed Bug (fixed)

migrations.test_commands.MakeMigrationsTests fail on Windows when run on a different drive than C:

Reported by: Zbigniew Siciarz Owned by: Zbigniew Siciarz
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Some of the test cases in MakeMigrationsTests fail on Windows due to inability to find a relative path between files located on separate drives.
The tests create a temporary migrations directory using tempfile.mkdtemp, which on Windows creates a directory under C:\Temp (or C:\Users\<username>\AppData\Local\Temp).

If one clones Django source code to a drive other than C:, then the makemigrations command tests fail with an error like the following (Windows 7, Python 3.5.1):

ERROR: test_makemigrations_non_interactive_not_null_alteration (migrations.test_commands.MakeMigrationsTests)
Traceback (most recent call last):
  File "D:\dev\django\tests\migrations\", line 834, in test_makemigrations_non_interactive_not_null_alteration
    call_command("makemigrations", "migrations", interactive=False, stdout=out)
  File "d:\dev\django\django\core\management\", line 130, in call_command
    return command.execute(*args, **defaults)
  File "d:\dev\django\django\core\management\", line 330, in execute
    output = self.handle(*args, **options)
  File "d:\dev\django\django\core\management\commands\", line 193, in handle
  File "d:\dev\django\django\core\management\commands\", line 211, in write_migration_files
    migration_string = os.path.relpath(writer.path)
  File "D:\Miniconda3\lib\", line 574, in relpath
    path_drive, start_drive))
ValueError: path is on mount 'C:', start on mount 'D:'

Since the value returned from relpath is used only for display and not for any I/O, I'd suggest catching this ValueError and using an absolute path in that case.

Change History (6)

comment:1 Changed 3 years ago by Zbigniew Siciarz

Owner: changed from nobody to Zbigniew Siciarz
Status: newassigned

comment:2 Changed 3 years ago by Zbigniew Siciarz

Has patch: set

The following pull request fixes this issue:

comment:3 Changed 3 years ago by Simon Charette

Triage Stage: UnreviewedAccepted

comment:4 Changed 3 years ago by Simon Charette

Keywords: tests removed
Patch needs improvement: set

Left some comments for improvement.

comment:5 Changed 3 years ago by Simon Charette

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Patch and added test LGTM.

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In f94ce0d2:

Fixed #27436 -- Fixed makemigrations crash when creating migrations on a separate drive than where Django is installed.

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