Skip to content

Don't exclude migrations from black #2138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ulgens
Copy link
Member

@ulgens ulgens commented Jul 27, 2025

The exclusion of migration files from black was presented in #1198

... The configuration file now has only basic hooks with the exclusion of migrations files.

I suppose this was considered a sane default, and I couldn't find any discussion about that exclusion in the PR. Considering that migration files are code, they are already revisioned and formatting them is Django's default behaviour; not excluding them makes feels more natural.

Relates to:

@ulgens ulgens requested a review from a team July 27, 2025 17:58
@ulgens ulgens self-assigned this Jul 27, 2025
@SaptakS
Copy link
Contributor

SaptakS commented Jul 28, 2025

I don't feel very strongly against or in support of this. I personally love black, but the only rationale I can think of excluding migrations is that it increases the migration file sizes a lot in attempt to make it more readable, and I am not sure that's necessary. I feel the number of migrations can become a lot, and with bigger file sizes, that don't need to be very readable, this may take more time in things like git cloning, etc.? Though maybe realistically not so much, hence I don't have a strong personal opinion against this PR.

@marksweb
Copy link
Contributor

I wouldn't format migration files. They rarely need reading and when they do, the long lines tend to be beneficial because you can [more] easily see all the field names in a model without the distraction of the attributes, for example.

ulgens added 3 commits July 28, 2025 11:51
So Django's auto formatter for generated files will pick it up

> Python files created by startproject, startapp, optimizemigration, makemigrations, and squashmigrations are now formatted using the black command if it is present on your PATH.

https://docs.djangoproject.com/en/5.2/releases/4.1/
@ulgens ulgens force-pushed the dont-exclude-migrations-from-black branch from 998b568 to 53db658 Compare July 28, 2025 08:52
@ulgens
Copy link
Member Author

ulgens commented Jul 28, 2025

@SaptakS I checked the before-and-after total file sizes. The difference is 12 KB. For comparison, foundation/migrations/0005_alter_approvedgrant_amount_currency_and_more.py file is 20 KB. The difference can easily be compensated for by squashing a single migration. Also, git is extremely scalable, and it can handle repositories with multiple hundreds of GBs in size (We are at 33 MB)

As an additional data point, this is GrandPerspective output for the project folder:

CleanShot 2025-07-28 at 12 06 25@2x

A single file in the .git folder is ~2000x bigger than the size difference created by the formatting.

@marksweb Thanks for the input. I don't personally disagree with your points, but I also don't strongly agree with them. Both points you mentioned are subjective, and the second one depends on personal taste, your IDE config, etc. As a tool, black's philosophy is

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

That approach aims to remove the need for this type of "how do we format things" questions and apply a consistent styling without requiring one to think about which rules to use or where to apply them. And again, Django's default is to format the generated files. For the sake of compliance with both tools' approaches and to avoid falling into the trap of bikeshedding, I think it's better to proceed with a minimal amount of customization.

@SaptakS
Copy link
Contributor

SaptakS commented Jul 28, 2025

Django's default is to format the generated files.

This point does make me more inclined to accepting this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants