Skip to content
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

Streamline logger adjustments for output #207

Closed
blueyed opened this issue Mar 2, 2022 · 1 comment · Fixed by #212
Closed

Streamline logger adjustments for output #207

blueyed opened this issue Mar 2, 2022 · 1 comment · Fixed by #212

Comments

@blueyed
Copy link
Contributor

blueyed commented Mar 2, 2022

The logging library is used for output processing.

For the lintmigrations command it gets adjusted here:

if options["verbosity"] > 1:
logging.basicConfig(format="%(message)s", level=logging.DEBUG)
elif options["verbosity"] == 0:
logger.disabled = True
else:
logging.basicConfig(format="%(message)s")

This gets not done with the integration into makemigrations:

def write_migration_files(self, changes):
super(Command, self).write_migration_files(changes)
if (
not getattr(settings, "MIGRATION_LINTER_OVERRIDE_MAKEMIGRATIONS", False)
and not self.lint
):
return
if self.dry_run:
"""
Since we rely on the 'sqlmigrate' to lint the migrations, we can only
lint if the migration files have been generated. Since the 'dry-run'
option won't generate the files, we cannot lint migrations.
"""
return
should_keep_migration = (
ask_should_keep_migration
if self.interactive
else default_should_keep_migration
)
# Lint migrations
linter = MigrationLinter(
path=os.environ["DJANGO_SETTINGS_MODULE"],
database=self.database,
no_cache=True,
exclude_migration_tests=self.exclude_migrations_tests,
warnings_as_errors=self.warnings_as_errors,
)
for app_label, app_migrations in changes.items():
if self.verbosity >= 1:
self.stdout.write(
self.style.MIGRATE_HEADING("Linting for '%s':" % app_label) + "\n"
)
for migration in app_migrations:
linter.lint_migration(migration)
if linter.has_errors:
if not should_keep_migration():
self.delete_migration(migration)
linter.reset_counters()

It would be good if this would behave in the same way, possibly by factoring it out.

It is especially an issue when using something like logging.basicConfig(level=logging.DEBUG) in manage.py.
It can be fixed by setting the logger's level explicitly, e.g. in Django's LOGGING setting, but then the adjustment of the logger based on verbosity would override it. This might be acceptable, although it should maybe depend on if the logger's level was set explicitly then?

@David-Wobrock
Copy link
Collaborator

Hi @blueyed

Thanks for the issue. Yes, we forgot to configure the logger for makemigrations.

I opened #212 let me know if you think this would solve the issue you're describing :)

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 a pull request may close this issue.

2 participants