From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Date: Mon, 6 Apr 2009 12:44:31 +0000 (+0000)
Subject: fix corner case like ~slice_id:[]
X-Git-Tag: PLCAPI-4.3-5~2
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=e2f484911ea86e0a055dc8bd31c1133f6c5785bf;p=plcapi.git

fix corner case like ~slice_id:[]
---

diff --git a/PLC/Filter.py b/PLC/Filter.py
index ba50d212..c90f7136 100644
--- a/PLC/Filter.py
+++ b/PLC/Filter.py
@@ -120,13 +120,18 @@ class Filter(Parameter, dict):
                     raise PLCInvalidArgument, "Invalid filter field '%s'" % field
 
                 if isinstance(value, (list, tuple, set)):
-                    # Turn empty list into (NULL) instead of invalid ()
+                    # handling filters like '~slice_id':[]
+                    # this should return true, as it's the opposite of 'slice_id':[] which is false
+                    # prior to this fix, 'slice_id':[] would have returned ``slice_id IN (NULL) '' which is unknown 
+                    # so it worked by coincidence, but the negation '~slice_ids':[] would return false too
                     if not value:
-                        value = [None]
-
-                    operator = "IN"
-                    value = map(str, map(api.db.quote, value))
-                    value = "(%s)" % ", ".join(value)
+                        field=""
+                        operator=""
+                        value = "FALSE"
+                    else:
+                        operator = "IN"
+                        value = map(str, map(api.db.quote, value))
+                        value = "(%s)" % ", ".join(value)
                 else:
                     if value is None:
                         operator = "IS"