#16160: Geojango syncdb fails if using post_syncdb sygnal on postgis
---------------------------------------------+----------------------------
 Reporter:  petr.gorodechnyj@…               |          Owner:  nobody
     Type:  Bug                              |         Status:  new
Milestone:                                   |      Component:  GIS
  Version:  1.3                              |       Severity:  Normal
 Keywords:  geojango postgresql post_syncdb  |   Triage Stage:  Unreviewed
Has patch:  0                                |  Easy pickings:  0
---------------------------------------------+----------------------------
 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.

 models.py:
 {{{
 from django.contrib.gis.db import models

 class Shop(models.Model):
     ....
     point               = models.PointField(null=True,
 spatial_index=False)
 }}}

 management.py:
 {{{
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16160>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to