simonw / django-sql-dashboard

Django app for building dashboards using raw SQL queries
https://django-sql-dashboard.datasette.io/
Apache License 2.0
437 stars 37 forks source link

Fix issue with Postgres 10 #138

Closed ryancheley closed 3 years ago

ryancheley commented 3 years ago

When using version 1.0 on Ubuntu 18.04 with Postgres 10.17 an Internal Server (500) error is generated.

I traced this back to the change made for version 1.0 on line 162 (see compared diff here)

The array_agg will throw the error

could not find array type for data type information_schema.sql_identifier

casting the column_name field to text resolves this issue for Postgres 10.

I did run the tests locally and 88 passed with 2 warnings. The warnings were:

test_project/test_utils.py::test_apply_sort[select * from (select * from foo) as results order by "bar"-bar-True-select * from (select * from foo) as results order by "bar" desc]
  /Users/ryan/github/django-sql-dashboard/venv/lib/python3.9/site-packages/django/db/backends/postgresql/base.py:304: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
    warnings.warn(

test_project/test_utils.py::test_apply_sort[select * from (select * from foo) as results order by "bar"-bar-True-select * from (select * from foo) as results order by "bar" desc]
  /Users/ryan/github/django-sql-dashboard:0: PytestWarning: Error when trying to teardown test databases: RuntimeError("generator didn't stop after throw()")

-- Docs: https://docs.pytest.org/en/stable/warnings.html
simonw commented 3 years ago

Thanks for figuring this out!

simonw commented 3 years ago

It would be great to have the GitHub Actions workflow run tests against multiple PostgreSQL versions to catch this kind of thing in the future https://github.com/simonw/django-sql-dashboard/blob/main/.github/workflows/test.yml

ryancheley commented 3 years ago

@simonw no problem! Sorry if the commit history looks wonky. As I was working through the contribution guidelines I found a typo which I fixed, but had messed up all of the branches on my local version and was trying to undo and redo and ... well, it's a holiday Sunday and I think it's time I go enjoy time with my family! Cheers!

simonw commented 3 years ago

Ryan wrote about this fix here: https://www.ryancheley.com/2021/07/09/contributing-to-django-sql-dashboard/