django-pgcli icon indicating copy to clipboard operation
django-pgcli copied to clipboard

Incompatibility with Django 3.1

Open jrheard opened this issue 5 years ago • 4 comments

Hi!

django-pgcli doesn't seem to be compatible with Django 3.1. Here's the issue I encountered:

🚂  pipenv run ./manage.py dbshell
Traceback (most recent call last):
  File "./manage.py", line 20, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/jrheard/.local/share/virtualenvs/djscoots-zK00EcLC-/Users/jrheard/.pyenv/shims/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/jrheard/.local/share/virtualenvs/djscoots-zK00EcLC-/Users/jrheard/.pyenv/shims/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jrheard/.local/share/virtualenvs/djscoots-zK00EcLC-/Users/jrheard/.pyenv/shims/python/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jrheard/.local/share/virtualenvs/djscoots-zK00EcLC-/Users/jrheard/.pyenv/shims/python/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/jrheard/.local/share/virtualenvs/djscoots-zK00EcLC-/Users/jrheard/.pyenv/shims/python/lib/python3.7/site-packages/django/core/management/commands/dbshell.py", line 26, in handle
    connection.client.runshell(options['parameters'])
TypeError: runshell() takes 1 positional argument but 2 were given

I think that this is related to https://github.com/django/django/commit/5b884d45ac5b76234eca614d90c83b347294c332 , a change made in Django 3.1 that modifies the signature of the .runshell() method.

I note that in that Django commit linked above, .runshell() was updated to take args self, parameters, but in https://github.com/ashchristopher/django-pgcli/blob/master/django_pgcli/init.py , django-pgcli's .runshell() takes args self.

That's about as deeply as I've looked into this issue - I'm not clear on the exact semantics of this parameters argument, and it's not immediately clear to me what django-pgcli should do with that argument. The main thing that I'm clear on is that the current release version of django-pgcli isn't compatible with Django 3.1 - hopefully it's an easy fix! 🙏

Thanks for making this library! :)

jrheard avatar Aug 31 '20 18:08 jrheard

This worked for me:

class PgCLIDatabaseClient(DatabaseClient):
    executable_name = 'pgcli'
    
    def runshell(self, parameters):
        PgCLIDatabaseClient.runshell_db(self.connection.get_connection_params(), parameters=parameters)

felipe-prenholato avatar Sep 03 '20 05:09 felipe-prenholato

For anyone who makes use of https://github.com/django-extensions/django-extensions in their project, I found it easier to just run:

pgcli $(./manage.py sqldsn --quiet --style=uri)

danlamanna avatar Jan 04 '21 19:01 danlamanna

This should hopefully fix it if it gets released in an updated version: https://github.com/ashchristopher/django-pgcli/pull/20

ddimmich avatar Mar 27 '21 14:03 ddimmich

Hi any chance it would be possible to merge https://github.com/ashchristopher/django-pgcli/pull/20 and release an updated version? Thank you!!!

ddimmich avatar Dec 05 '22 14:12 ddimmich