jazzband/django-configurations

Breaks use of `--config` arguments in management commands

PeterJCLaw opened this issue · 0 comments

If a project wants to use django-configurations then doing so precludes the use of --config (or any other shortening of --configuration) in all the management commands in the project, including those inherited from other packages.

This appears to be due to the default behaviour of argparse.ArgumentParser, specifically the allow_abbrev argument, in combination with they way that ConfigurationImporter checks for the configuration to use from the command line -- namely by running Django's argument parser before any other arguments have been added.

I'm hitting this with https://github.com/thread/django-lightweight-queue/, whose queue_runner command has a --config which is being hidden by this behaviour. The result of which is that queue_runner --config=./special-config.py results in an AttributeError: "Couldn't find configuration './special-config.py' in module '.settings'".

While in some cases it may be possible to change to just not using conflicting argument names, this won't always be possible if, for example, the name comes from a separate library.

I suspect it may be possible to fix this in django-configurations by changing ConfigurationImporter to set allow_abbrev=False in the parser it creates in check_options, though I realise this might be considered a breaking change.