Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#34607 closed Uncategorized (invalid)

function st_geomfromwkb(bytea) does not exist - geodjango tutorial

Reported by: bjoh-01 Owned by: nobody
Component: GIS Version: 4.2
Severity: Normal Keywords: geodjango, postgis
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm encountering some issues when trying to follow the world app geodjango tutorial step by step as documented: https://docs.djangoproject.com/en/4.2/ref/contrib/gis/tutorial/

I had trouble with this error when trying to complete the layermapping step: https://docs.djangoproject.com/en/4.2/ref/contrib/gis/tutorial/#layermapping

So I skipped that and encountered it again when trying the spatial lookups: https://docs.djangoproject.com/en/4.2/ref/contrib/gis/tutorial/#spatial-lookups

ogrinspect worked so I assume I have geos and gdal libraries configured correctly. My database is confirmed to have POSTGIS 3.0. https://docs.djangoproject.com/en/4.2/ref/contrib/gis/tutorial/#spatial-lookups

Traceback:

(InteractiveConsole)
>>> pnt_wkt = "POINT(-95.3385 29.7245)"
>>> from world.models import WorldBorder
>>> WorldBorder.objects.filter(mpoly__contains=pnt_wkt)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 1436, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 1454, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 1461, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1502, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1533, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1383, in build_filter
    lookups, parts, reffed_expression = self.solve_lookup_type(arg, summarize)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1193, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1681, in names_to_path
    raise FieldError(
django.core.exceptions.FieldError: Cannot resolve keyword 'mpoly' into field. Choices are: area, fips, geom, id, iso2, iso3, lat, lon, name, pop2005, region, subregion, un
>>> WorldBorder.objects.filter(geom__contains=pnt_wkt)
Traceback (most recent call last):
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedFunction: function st_geomfromewkb(bytea) does not exist
LINE 1: ...er" WHERE ST_Contains("world_worldborder"."geom", ST_GeomFro...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 374, in __repr__
    data = list(self[: REPR_OUTPUT_SIZE + 1])
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 380, in __len__
    self._fetch_all()
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1560, in execute_sql
    cursor.execute(sql, params)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/vboxuser/Desktop/django/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: function st_geomfromewkb(bytea) does not exist
LINE 1: ...er" WHERE ST_Contains("world_worldborder"."geom", ST_GeomFro...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Change History (2)

comment:1 by Natalia Bidart, 19 months ago

Resolution: invalid
Status: newclosed

Hello!

Given the first error in your console output (django.core.exceptions.FieldError: Cannot resolve keyword 'mpoly' into field.), this report looks like a result of some misconfiguration, since in the tutorial the WorldBorder model class clearly has a mpoly field.

So, with the information provided so far, this does not seem an issue with Django itself.The advice is then to follow the bug reporting guide and seek help in the Django User channels to evaluate whether your problem is caused by a configuration issue.

Closing as invalid for now, if you find a concrete bug in Django itself or in the docs, let us know and we'll analyze this further. Thanks!

comment:2 by Natalia Bidart, 19 months ago

As an extra data point, and since I never used GeoDjango before, I followed the tutorial and I did not encounter any issues. I used an Ubuntu system with PG 12 and PostGIS 3.3

gisdb=# SELECT postgis_full_version();
                                                                         postgis_full_version                           
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.3.2 4975da8" [EXTENSION] PGSQL="120" GEOS="3.8.0-CAPI-1.13.1 " PROJ="6.3.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)"

Resulting in a working WorldBorder model:

>>>WorldBorder.objects.filter(mpoly__contains=pnt_wkt)
<QuerySet [<WorldBorder: United States>]>
Note: See TracTickets for help on using tickets.
Back to Top