GeoDjango syncdb fails if using post_syncdb signal on postgis to access geometry columns
|Reported by:||petr.gorodechnyj@…||Owned by:||nobody|
|Severity:||Normal||Keywords:||geodjango postgresql post_syncdb|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I use geojango on Postgresql 8.4 with the help of postgis 1.5. When I create model with geo field and use it as is - that's ok. But in my case I need to do some serious stuff on DB level so I created couple of postgresql sql-functions. So I wrote sql and execute it in post_syncdb signal handler.
from django.contrib.gis.db import models class Shop(models.Model): .... point = models.PointField(null=True, spatial_index=False)
from django.db.models.signals import post_syncdb def post_syncdb_task(sender, **kwargs): from django.db import connection cursor = connection.cursor() sql = '''CREATE OR REPLACE FUNCTION functionname(integer, text) RETURNS double precision AS $$ SELECT ST_distance_sphere(point, ST_GeomFromEWKT($2)) as d FROM this_package_shop WHERE this_package_shop.id = $1; $$ LANGUAGE SQL;''' cursor.execute(sql); from this_package import models as this_models post_syncdb.connect(post_syncdb_task, sender=this_models)
When I execute syncdb on non-existing table, e.g. in python manage.py test I get:
File "/home/gorodechnyj/workspace/projectname/this_package/management.py", line 18, in post_syncdb_task cursor.execute(sql); File "/usr/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute return self.cursor.execute(query, args) django.db.utils.DatabaseError: column "point" does not exist LINE 2: SELECT ST_distance_sphere(point, ST_GeomFrom...
And most peculiar thing: there's really no trace of field point at all! It is simply not being created.
If I disable my post_syncdb handler, error dissapears and field "point" is being created but not sql functions.
So no testing on code which use them can be performed.
Change History (5)
comment:1 Changed 3 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Summary changed from Geojango syncdb fails if using post_syncdb sygnal on postgis to Geojango syncdb fails if using post_syncdb signal on postgis
comment:3 Changed 3 years ago by anonymous
- Keywords geodjango added; geojango removed
- Summary changed from Geojango syncdb fails if using post_syncdb signal on postgis to GeoDjango syncdb fails if using post_syncdb signal on postgis to access geometry columns
- Type changed from Bug to New feature