Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27603 closed Bug (fixed)

on SpatiaLite AsKML GIS function fails if annotated queryset is evaluated several times

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: GIS Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [2]: qs = City.objects.annotate(kml=AsKML('point')) 
                         
In [3]: qs.first().kml                                         
Out[3]: u'<Point><coordinates>1,1</coordinates></Point>'
                                                   
In [4]: qs.first().kml
                                                                                             
In [5]: qs.first().kml                                                    
---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-5-e1dac47e2e4f> in <module>()
----> 1 qs.first().kml               

/home/sergey/dev/django/django/db/models/query.pyc in first(self)                 
    558         Returns the first object of a query, returns None if no match is found.
    559         """      
--> 560         objects = list((self if self.ordered else self.order_by('pk'))[:1])
    561         if objects:
    562             return objects[0]              

/home/sergey/dev/django/django/db/models/query.pyc in __iter__(self)                       
    247                - Responsible for turning the rows into model objects.
    248         """                              
--> 249         self._fetch_all()                                  
    250         return iter(self._result_cache)
    251                                              

/home/sergey/dev/django/django/db/models/query.pyc in _fetch_all(self)
   1072     def _fetch_all(self):
   1073         if self._result_cache is None:
-> 1074             self._result_cache = list(self.iterator())
   1075         if self._prefetch_related_lookups and not self._prefetch_done:
   1076             self._prefetch_related_objects()
                                                                      
/home/sergey/dev/django/django/db/models/query.pyc in __iter__(self)
     50         # Execute the query. This will also fill compiler.select, klass_info,                                                        
     51         # and annotations.
---> 52         results = compiler.execute_sql() 
     53         select, klass_info, annotation_col_map = (compiler.select, compiler.klass_info,
     54                                                   compiler.annotation_col_map)

/home/sergey/dev/django/django/db/models/sql/compiler.pyc in execute_sql(self, result_type)                                                                                                            
    827         cursor = self.connection.cursor()
    828         try:                              
--> 829             cursor.execute(sql, params)
    830         except Exception:              
    831             cursor.close()                            

/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql, params)
     77         start = time()                               
     78         try:         
---> 79             return super(CursorDebugWrapper, self).execute(sql, params)
     80         finally:                                              
     81             stop = time()
                                                                                                                                             
/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql, params)
     62                 return self.cursor.execute(sql)
     63             else:
---> 64                 return self.cursor.execute(sql, params)                                                                                                                                        
     65                                                 
     66     def executemany(self, sql, param_list):
                      
/home/sergey/dev/django/django/db/utils.pyc in __exit__(self, exc_type, exc_value, traceback)
     92                 if dj_exc_type not in (DataError, IntegrityError):
     93                     self.wrapper.errors_occurred = True            
---> 94                 six.reraise(dj_exc_type, dj_exc_value, traceback)  
     95                                     
     96     def __call__(self, func):

/home/sergey/dev/django/django/db/backends/utils.pyc in execute(self, sql, params)
     62                 return self.cursor.execute(sql)                                
     63             else:
---> 64                 return self.cursor.execute(sql, params)                    
     65                    
     66     def executemany(self, sql, param_list):

/home/sergey/dev/django/django/db/backends/sqlite3/base.pyc in execute(self, query, params)
    327             return Database.Cursor.execute(self, query)              
    328         query = self.convert_query(query)
--> 329         return Database.Cursor.execute(self, query, params)
    330                                        
    331     def executemany(self, query, param_list):

OperationalError: wrong number of arguments to function AsKML()

Change History (6)

comment:1 by Sergey Fedoseev, 7 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Tim Graham, 7 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 7 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In e9149d3:

Fixed #27603 -- Fixed AsKML when queryset is evaluated more than once.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In b6a6787f:

[1.11.x] Fixed #27603 -- Fixed AsKML when queryset is evaluated more than once.

Backport of e9149d3eb0ed0ddc8b27b1990eb2b7293c1231cd from master

comment:6 by Tim Graham <timograham@…>, 7 years ago

In 3905cfa1:

Fixed #28353 -- Fixed some GIS functions when queryset is evaluated more than once.

Reverted test for refs #27603 in favor of using FuncTestMixin.

Note: See TracTickets for help on using tickets.
Back to Top