bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.45k stars 424 forks source link

impossible to use tenant_command for a command with arguments. #645

Open feenes opened 4 years ago

feenes commented 4 years ago

I'm having a management command of the kind

class Command(BaseCommand):
    help = "test command"
    def add_arguments(self, parser):
        parser.add_argument(
            "someargs",
            nargs="+",
            help="justsomeargs",
        )
    def handle(self, *args, **options):
        print("someargs =", options["someargs"])

When trying to call with manage.py tenant_command test_command -s tenant 123

I receive

manage.py tenant_command: error: unrecognized arguments: 123

I also tried manage.py tenant_command test_command -- 123

Also without success.

Is there any fix / work around?

This can also be reproduced with a simple command like:

./manage.py tenant_command -s tenant dumpdata appname

which will give:

manage.py tenant_command: error: unrecognized arguments: appname
ratondeau commented 4 years ago

Same here. If I try to django-admin tenant_command changepassword api.user --schema=obaldo

I get an error message: django-admin tenant_command: error: unrecognized arguments: api.user

I guess tennant commando must be told that it has to call the changepassword with the following argument and not to use that argument itself.

Version according to pipenv: 1.10.0

twkrol commented 3 years ago

I had conflict with my own parameter name 's'. Workaround: when I changed it to other letter, now it works as expected, eg. can invoke python manage.py tenant_command mycommand -myparam --schema:tenant1

ajharry69 commented 1 year ago

As a workaround, you can use:-

python manage.py tenant_command --schema=tenant shell
>>> from django.core.management import call_command
>>> call_command('command_expecting_arguments', 'argument1')
jmarxuach commented 8 months ago

Fix is not included in 1.12. So as a workaround for dumpdata use this :

python manage.py tenant_command --schema=tenant shell
>>> from django.core.management import call_command
>>> with open('model_name.json', 'w') as f:
       call_command('dumpdata', 'app_name.model_name', stdout=f)