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
         kwargs['internal'] = 'automatic'
72
         kwargs['internal'] = 'automatic'
73
         super(self.__class__, self).__init__(primary_key = True, **kwargs)
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
     def construct_data(self, emcomponent, fname, datas, cur_value):
75
     def construct_data(self, emcomponent, fname, datas, cur_value):
79
         if cur_value is None:
76
         if cur_value is None:
80
             #Ask datasource to provide a new uniqID
77
             #Ask datasource to provide a new uniqID

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

290
                 err_l[field] = ret
290
                 err_l[field] = ret
291
                 continue
291
                 continue
292
             field_datahandler = self._target_class.field(field)
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
             if ref_field is not None and not field_datahandler.is_reference():
298
             if ref_field is not None and not field_datahandler.is_reference():
294
                 # inconsistency
299
                 # inconsistency
295
                 err_l[field] = NameError(   "The field '%s' in %s is not \
300
                 err_l[field] = NameError(   "The field '%s' in %s is not \
658
     # @throw LeApiQueryError if unknown field given
663
     # @throw LeApiQueryError if unknown field given
659
     def set_field_list(self, field_list):
664
     def set_field_list(self, field_list):
660
         err_l = dict()
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
     ##@brief Execute the get query
679
     ##@brief Execute the get query
674
     def execute(self, datas = None):
680
     def execute(self, datas = None):
678
     # @returns a list containing the item(s)
684
     # @returns a list containing the item(s)
679
     def _query(self, datas = None):
685
     def _query(self, datas = None):
680
         # select datas corresponding to query_filter
686
         # select datas corresponding to query_filter
687
+        fl = list(self._field_list) if self._field_list is not None else None
681
         l_datas=self._ro_datasource.select( 
688
         l_datas=self._ro_datasource.select( 
682
             target = self._target_class,
689
             target = self._target_class,
683
-            field_list = list(self._field_list),
690
+            field_list = fl,
684
             filters = self._query_filter[0],
691
             filters = self._query_filter[0],
685
             relational_filters = self._query_filter[1],
692
             relational_filters = self._query_filter[1],
686
             order = self._order,
693
             order = self._order,

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

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

Loading…
Cancel
Save