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

Management command fails with latest version #613

Open abdulMuneerM opened 4 years ago

abdulMuneerM commented 4 years ago

Tried to run the management command by using tenant_command, but I am getting following error. manage.py tenant_command: error: unrecognized arguments: --username user

It was working before upgrading. How to solve it?

jeroenbrouwer commented 4 years ago

The 1.10.0 release broke it I think... I recommend switching back to 1.9.0 for the moment. The problem lies in https://github.com/bernardopires/django-tenant-schemas/commit/7f72d7af039e6cf2a15520d525636d6e11e72efc#diff-4c79357a33bc89ce66cca6394a8d45bf

This commit prevents taking additional arguments into account...

abdulMuneerM commented 4 years ago

Exactly, I reverted to 1.9.0 for now and it's working fine. Hope the fix will be added on next release.

jeroenbrouwer commented 4 years ago

@goodtune can you take a look at this issue? It basically broke some basic features of this package...

One way to easily add the arguments back would be to do something like the following in InteractiveTenantOption:

def add_arguments(self, parser):
        parser.add_argument("command")
        parser.add_argument(
            "-s", "--schema", dest="schema_name", help="specify tenant schema"
        )
        parser.add_argument("command_args", nargs=argparse.REMAINDER)

and in tenant_command:

def handle(self, command, command_args, schema_name, *args, **options):
        tenant = self.get_tenant_from_options_or_interactive(
            schema_name=schema_name, **options
        )
        connection.set_tenant(tenant)
        call_command(command, *command_args, *args, **options)
goodtune commented 4 years ago

Pull request welcome.

ivancdechiara commented 4 years ago

In the version 1.10.0, the command changed to:

python manage.py tenant_command createsuperuser