Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue running sqldiff on Postgres 13/Postgis using a geometry field #1652

Open
danaspiegel opened this issue Apr 15, 2021 · 3 comments · May be fixed by #1860
Open

Issue running sqldiff on Postgres 13/Postgis using a geometry field #1652

danaspiegel opened this issue Apr 15, 2021 · 3 comments · May be fixed by #1860

Comments

@danaspiegel
Copy link

Not sure if this is a bug, but perhaps, and I'm happy to help debug, but here goes:

When I run sqldiff on a PG 13 database with PostGIS installed (on Mac OS X big sur) that has a geometry field:

    location = django.contrib.gis.db.models.PointField(_('location (lat / long)'), blank=True, null=True)

I get this error:

Traceback (most recent call last):
  File "./manage.py", line 21, in <module>
    main()
  File "./manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 1380, in run_from_argv
    super().run_from_argv(argv)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 1367, in execute
    super().execute(*args, **options)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/utils.py", line 62, in inner
    ret = func(self, *args, **kwargs)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 1360, in handle
    sqldiff_instance.find_differences()
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 676, in find_differences
    self.find_field_type_differ(meta, table_description, table_name)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 550, in find_field_type_differ
    db_type = self.get_field_db_type(description, field, table_name)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 1182, in get_field_db_type
    db_type = super().get_field_db_type(description, field, table_name)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django_extensions/management/commands/sqldiff.py", line 342, in get_field_db_type
    reverse_type, geo_params = self.introspection.get_geometry_type(table_name, geo_col)
  File "/Users/dana/.local/share/virtualenvs/lucidgreen-consumer-jem90h-L/lib/python3.8/site-packages/django/contrib/gis/db/backends/postgis/introspection.py", line 43, in get_geometry_type
    """, (table_name, description.name))
AttributeError: 'str' object has no attribute 'name'

Digging into the code, there is a call to get_geometry_type from sqldiff.py (L338):

        if reverse_type == 'GeometryField':
            geo_col = description[0]
            # Getting a more specific field type and any additional parameters
            # from the `get_geometry_type` routine for the spatial backend.
            reverse_type, geo_params = self.introspection.get_geometry_type(table_name, geo_col)
            if geo_params:
                kwargs.update(geo_params)
            reverse_type = 'django.contrib.gis.db.models.fields.%s' % reverse_type

get_geometry_type seems to want to be called with table_name and description, not geo_col.

If I change the call to get_geometry_type to take description, sqldiff command seems to work.

This seems like a simple change to make, but I'm curious if this is something other users have seen.

@pennersr
Copy link

I just bumped into the exact same issue -- so I can confirm that this is a bug (django-extensions==3.1.3).

@sheeshee
Copy link

sheeshee commented Jun 9, 2022

I've just encountered this issue too django-extensions==3.1.5

@stianjensen
Copy link

Yes, see the same issue with postgis (django-extensions==3.2.3)

wadewilliams added a commit to wadewilliams/django-extensions that referenced this issue Feb 6, 2024
@wadewilliams wadewilliams linked a pull request Feb 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants