Re: [Django] #14161: GeoDjango autofield makes transaction fail

2010-08-24 Thread Django
#14161: GeoDjango autofield makes transaction fail
+---
  Reporter:  miguel.araujo.pe...@gmail.com  | Owner:  nobody
   
Status:  closed | Milestone:
   
 Component:  GIS|   Version:  1.2   
   
Resolution:  fixed  |  Keywords:  postGIS, 
autofield, geodjango
 Stage:  Unreviewed | Has_patch:  0 
   
Needs_docs:  0  |   Needs_tests:  0 
   
Needs_better_patch:  0  |  
+---
Changes (by miguel.araujo.pe...@gmail.com):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => fixed
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 I'm look at this at the moment while I was debugging django code to see If
 I could see where the bug is and submit a patch.

 The bug of course is in my code. I should be doing:

 {{{
 spot = Spot(code="park", poly=Point(10,10))
 spot.save()
 }}}

 which I'm pretty sure I tried yesterday night and didn't work, but I guess
 I misspelled something and I didn't notice (late hacking). This is such
 dumb ticket. I'm very sorry about it, please delete it.

-- 
Ticket URL: 
Django 
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 django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14161: GeoDjango autofield makes transaction fail

2010-08-23 Thread Django
#14161: GeoDjango autofield makes transaction fail
---+
 Reporter:  miguel.araujo.pe...@gmail.com  |   Owner:  nobody
   Status:  new|   Milestone:
Component:  GIS| Version:  1.2   
 Keywords:  postGIS, autofield, geodjango  |   Stage:  Unreviewed
Has_patch:  0  |  
---+
 Hi there,

 This is my GeoDjango model:


 {{{
 from django.contrib.gis.db import models
 from django.db.models import fields

 class Spot(models.Model):
 idSpot = fields.AutoField(primary_key = True)

 code = models.CharField(max_length = 30)

 poly = models.PointField(spatial_index = True,
 srid = 4326,
 geography = True)

 objects = models.GeoManager()
 }}}

 When I do this:
 {{{
 python manage.py shell

 from location.models import Spot
 from django.contrib.gis.geos import Point
 spot = Spot("park",Point(10,10))
 spot.save()
 }}}

 What I get is:
 {{{
 ---
 ValueErrorTraceback (most recent call
 last)

 /home/map/mercurial/telollevo/src/telollevogis/ in
 ()

 /usr/local/lib/python2.6/dist-packages/django/db/models/base.pyc in
 save(self, force_insert, force_update, using)
 433 if force_insert and force_update:
 434 raise ValueError("Cannot force both insert and
 updating in model saving.")
 --> 435 self.save_base(using=using, force_insert=force_insert,
 force_update=force_update)
 436
 437 save.alters_data = True

 /usr/local/lib/python2.6/dist-packages/django/db/models/base.pyc in
 save_base(self, raw, cls, origin, force_insert, force_update, using)
 495 # Determine whether a record with the primary key
 already exists.

 496 if (force_update or (not force_insert and
 --> 497
 manager.using(using).filter(pk=pk_val).exists())):
 498 # It does already exist, so do an UPDATE.

 499 if force_update or non_pks:

 /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyc in
 filter(self, *args, **kwargs)
 548 set.
 549 """
 --> 550 return self._filter_or_exclude(False, *args, **kwargs)
 551
 552 def exclude(self, *args, **kwargs):

 /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyc in
 _filter_or_exclude(self, negate, *args, **kwargs)
 566 clone.query.add_q(~Q(*args, **kwargs))
 567 else:
 --> 568 clone.query.add_q(Q(*args, **kwargs))
 569 return clone
 570

 /usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.pyc in
 add_q(self, q_object, used_aliases)
1129 else:
1130 self.add_filter(child, connector,
 q_object.negated,
 -> 1131 can_reuse=used_aliases)
1132 self.where.end_subtree()
1133 if connector == OR:

 /usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.pyc in
 add_filter(self, filter_expr, connector, negate, trim, can_reuse,
 process_extras)
1069 else:
1070 self.where.add((Constraint(alias, col, field),
 lookup_type, value),
 -> 1071 connector)
1072
1073 if negate:

 /usr/local/lib/python2.6/dist-
 packages/django/contrib/gis/db/models/sql/where.pyc in add(self, data,
 connector)
  39  isinstance(obj.field, GeometryField) ):
  40 data = (GeoConstraint(obj), lookup_type, value)
 ---> 41 super(GeoWhereNode, self).add(data, connector)
  42
  43 def make_atom(self, child, qn, connection):

 /usr/local/lib/python2.6/dist-packages/django/db/models/sql/where.pyc in
 add(self, data, connector)
  64
  65 if hasattr(obj, "prepare"):
 ---> 66 value = obj.prepare(lookup_type, value)
  67 super(WhereNode, self).add((obj, lookup_type,
 annotation, value),
  68 connector)

 /usr/local/lib/python2.6/dist-packages/django/db/models/sql/where.pyc in
 prepare(self, lookup_type, value)
 297 def prepare(self, lookup_type, value):
 298 if self.field:
 --> 299 return self.field.get_prep_lookup(lookup_type, value)
 300 return value
 301

 /usr/local/lib/python2.6/dist-
 packages/django/db/models/fields/__init__.pyc in get_prep_lookup(self,
 lookup_type, value)
 290 return value
 291 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'):
 --> 292 return self.get_prep_value(value)
 293 elif lookup_type in ('range', 'in'):
 294 return [self.ge