question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dev Environment: Makemigrations Files Fails Linting Tests

See original GitHub issue

Environment

  • Python version: Development Environment
  • Nautobot version: 1.0.0b2

Steps to Reproduce

  1. Update models that create a migration
  2. Run invoke build
  3. Run invoke makemigrations
  4. File is created with root:root user account
  5. Black is unable to run
  6. File does not meet black standards (I know, Django doing it, not the project)

Expected Behavior

Expected a migration file to pass linting without needing additional steps

Observed Behavior

Files had to have ownership changed to be able to blacken the file, then needing to black.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jathanismcommented, Apr 3, 2021

I don’t really have an issue w/ excluding migrations from black seeing as the majority of them are automatically generated, but I do have an issue with the motivation for it being that we have two supported development patterns, and one of them isn’t playing nicely.

0reactions
glennmatthewscommented, May 28, 2021

As discussed above, this issue describes two distinct problems:

  1. Django’s autogenerated migration code doesn’t comply with Black
  2. Files created from within the Docker dev environment (such as generated migrations) appear with the wrong file ownership on the host system.

For item 1, this is an annoyance but easy enough to solve by running Black against the migrations after they are generated. Since we don’t have any control over the code generated by Django, the only other option would be to exclude migrations from Black’s checking, and after some discussion amongst the core team we don’t feel that doing that would be desirable. The benefit of having consistent code style across the entire project, including migrations, outweighs the inconvenience.

For item 2, this is a notable flaw in the current Docker development environment. More discussion amongst the core team revealed that most of the core team are not actually using the Docker development environment but instead a hybrid virtualenv + Docker services environment that’s not currently documented as a workflow, but avoids the file permissions issue naturally. I’ve opened #507 to track the work needed to document this hybrid workflow as the actual, preferred development workflow for Nautobot.

Thank you for opening this issue - it sparked some important conversations!

Read more comments on GitHub >

github_iconTop Results From Across the Web

3YOURMIND/django-migration-linter - GitHub
The linter analysed all migrations from the Django project. It found 3 migrations that are doing backward incompatible operations and 1 that is...
Read more >
Testing Django Migrations - sobolevn.me
We lint migration files with wemake-python-styleguide , it drastically reduces the possibility of bad code inside the migration files; We use ...
Read more >
django-migration-linter - PyPI
Detect backward incompatible migrations for your django project.
Read more >
Set up tests, linters and type checking in Python projects in 2020
Set up tests, linters and type checking in Python projects in 2020 · Before starting · Testing · Code coverage · Linting ·...
Read more >
Database creation failing during django testing - Stack Overflow
I don't think that's a good idea tbh, django migrations are very picky and might need a full database reboot if things get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found