Fixed drop test database command with psycopg 3 #1818
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the current main branch, when executing drop_test_databaes with only psycopg v3 installed, there is a trace, see below.
This PR fixes the command when psycopg v3 is installed. It is backwards compatible with psycopg2.
Traceback (most recent call last):
File "/home/jannh/git/siam/manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django/core/management/init.py", line 442, in execute_from_command_line
utility.execute()
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django/core/management/init.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django_extensions/management/utils.py", line 62, in inner
ret = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/django_extensions/management/commands/drop_test_database.py", line 187, in handle
connection = Database.connect(**conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/psycopg/connection.py", line 720, in connect
conninfo = make_conninfo(**params)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/psycopg/conninfo.py", line 59, in make_conninfo
_parse_conninfo(conninfo)
File "/home/jannh/.virtualenvs/siam/lib/python3.11/site-packages/psycopg/conninfo.py", line 98, in _parse_conninfo
raise e.ProgrammingError(str(ex))
psycopg.ProgrammingError: invalid connection option "database"