Browse Source

Bugfixes on filters handling

- calling check_data_value on filters value to ensure value casting
Yann Weber 8 years ago
parent
commit
9c3a770610
3 changed files with 20 additions and 16 deletions
  1. 0
    3
      lodel/leapi/datahandlers/datas.py
  2. 19
    12
      lodel/leapi/query.py
  3. 1
    1
      plugins/mongodb_datasource/datasource.py

+ 0
- 3
lodel/leapi/datahandlers/datas.py View File

@@ -72,9 +72,6 @@ class UniqID(Integer):
72 72
         kwargs['internal'] = 'automatic'
73 73
         super(self.__class__, self).__init__(primary_key = True, **kwargs)
74 74
 
75
-    def _check_data_value(self, value):
76
-        return value, None
77
-
78 75
     def construct_data(self, emcomponent, fname, datas, cur_value):
79 76
         if cur_value is None:
80 77
             #Ask datasource to provide a new uniqID

+ 19
- 12
lodel/leapi/query.py View File

@@ -290,6 +290,11 @@ field name" % fieldname)
290 290
                 err_l[field] = ret
291 291
                 continue
292 292
             field_datahandler = self._target_class.field(field)
293
+            # Casting value given datahandler
294
+            value, error = field_datahandler._check_data_value(value)
295
+            if isinstance(error, Exception):
296
+                err_l[field] = error
297
+                continue
293 298
             if ref_field is not None and not field_datahandler.is_reference():
294 299
                 # inconsistency
295 300
                 err_l[field] = NameError(   "The field '%s' in %s is not \
@@ -658,17 +663,18 @@ class LeGetQuery(LeFilteredQuery):
658 663
     # @throw LeApiQueryError if unknown field given
659 664
     def set_field_list(self, field_list):
660 665
         err_l = dict()
661
-        for fieldname in field_list:
662
-            ret = self._check_field(self._target_class, fieldname)
663
-            if isinstance(ret, Exception):
664
-                msg = "No field named '%s' in %s"
665
-                msg %= (fieldname, self._target_class.__name__)
666
-                expt = NameError(msg)
667
-                err_l[fieldname] =  expt
668
-        if len(err_l) > 0:
669
-            msg = "Error while setting field_list in a get query"
670
-            raise LeApiQueryErrors(msg = msg, exceptions = err_l)
671
-        self._field_list = list(set(field_list))
666
+        if field_list is not None:
667
+            for fieldname in field_list:
668
+                ret = self._check_field(self._target_class, fieldname)
669
+                if isinstance(ret, Exception):
670
+                    msg = "No field named '%s' in %s"
671
+                    msg %= (fieldname, self._target_class.__name__)
672
+                    expt = NameError(msg)
673
+                    err_l[fieldname] =  expt
674
+            if len(err_l) > 0:
675
+                msg = "Error while setting field_list in a get query"
676
+                raise LeApiQueryErrors(msg = msg, exceptions = err_l)
677
+            self._field_list = list(set(field_list))
672 678
     
673 679
     ##@brief Execute the get query
674 680
     def execute(self, datas = None):
@@ -678,9 +684,10 @@ class LeGetQuery(LeFilteredQuery):
678 684
     # @returns a list containing the item(s)
679 685
     def _query(self, datas = None):
680 686
         # select datas corresponding to query_filter
687
+        fl = list(self._field_list) if self._field_list is not None else None
681 688
         l_datas=self._ro_datasource.select( 
682 689
             target = self._target_class,
683
-            field_list = list(self._field_list),
690
+            field_list = fl,
684 691
             filters = self._query_filter[0],
685 692
             relational_filters = self._query_filter[1],
686 693
             order = self._order,

+ 1
- 1
plugins/mongodb_datasource/datasource.py View File

@@ -448,7 +448,7 @@ class MongoDbDatasource(object):
448 448
                 if fieldname in res:
449 449
                     logger.warning("Dropping previous condition. Overwritten \
450 450
 by an equality filter")
451
-                res[fieldname] = str(value)
451
+                res[fieldname] = value
452 452
                 continue
453 453
             if fieldname in eq_fieldname:
454 454
                 logger.warning("Dropping condition : '%s %s %s'" % (

Loading…
Cancel
Save