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

Unable to run shell for a specifc schema via tenant_command #634

Open sshahbaj opened 4 years ago

sshahbaj commented 4 years ago

Environment:

I'm having trouble executing the shell command for a specific schema. Here is the command that I'm trying to run:

python manage.py tenant_command shell --schema=<SCHEMA_NAME>

And I'm getting this error:

Traceback (most recent call last):
  File "manage.py", line 25, in <module>
    main()
  File "manage.py", line 21, in main
    execute_from_command_line(sys.argv)
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/tenant_schemas/management/commands/tenant_command.py", line 15, in handle
    call_command(command, *args, **options)
  File "/home/cypher/.virtualenvs/candi-server/lib/python3.6/site-packages/django/core/management/__init__.py", line 160, in call_command
    ', '.join(sorted(valid_options)),
TypeError: Unknown option(s) for shell command: skip_checks. Valid options are: command, force_color, help, interface, no_color, no_startup, pythonpath, settings, stderr, stdout, traceback, verbosity, version.
sshahbaj commented 4 years ago

Looks like adding the requires_system_checks flag and setting it to False in tenant_command.py fixes the problem.

class Command(InteractiveTenantOption, BaseCommand):
    help = "Wrapper around django commands for use with an individual tenant"
    requires_system_checks = False

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

Is this issue caused due to #613 ?

sshahbaj commented 4 years ago

Ok, I downgraded to Django v2.2.12 and django-tenant-schemas to 1.9.0 and it also works.

asrocha commented 4 years ago

@sshahbaj where I found this file ?

sshahbaj commented 4 years ago

@asrocha Here