15five / scim2-filter-parser

A customizable parser/transpiler for SCIM2.0 filters
Other
23 stars 8 forks source link

Use exact when comparing against boolean values #53

Closed JPDSousa closed 4 months ago

JPDSousa commented 4 months ago

Closes #49

Equality predicates against boolean values will now transpile to Q(fieldX__exact=True/False). This avoids using the SQL UPPER function, which at least in PostgreSQL fails, as the function requires a string as input.

Transpiler.lookup_op now takes the comparison value as well, and uses both the SCIM operation and the comparison value to decide on the appropriate Django operator.

logston commented 4 months ago

Looks good! Just has one lint error to fix:

ruff: commands[1]> poetry run ruff check src                                                                                                                                                                           
All checks passed!                                                                                                                                                                                                     
ruff: commands[2]> poetry run ruff format --check --diff src                                                                                                                                                           
--- src/scim2_filter_parser/transpilers/django_q_object.py                                                                                                                                                             
+++ src/scim2_filter_parser/transpilers/django_q_object.py                                                                                                                                                             
@@ -231,10 +231,10 @@                                                                                                                                                                                                  
         if not op:                                                                                                                                                                                                    
             raise ValueError(f"Unknown Django op {op_code}")                                                                                                                                                          

-        if isinstance(comp_value, bool) and op == 'iexact':                                                                                                                                                           
+        if isinstance(comp_value, bool) and op == "iexact":                                                                                                                                                           
             # Use "exact" for boolean values, as certain DB drivers (e.g., Postgres) will transpile                                                                                                                   
             #  "<field> iexact true/false" to "UPPER(field::text) = UPPER(true/false), which fails.                                                                                                                   
             #  UPPER requires a string.                                                                                                                                                                               
-            return 'exact'                                                                                                                                                                                            
+            return "exact"                                                                                                                                                                                            

         return op or node_value                                                                                                                                                                                       

1 file would be reformatted, 9 files already formatted                                                                                                                                                                 
ruff: exit 1 (0.21 seconds) /Users/paul/Code/15five/scim2-filter-parser> poetry run ruff format --check --diff src pid=22696                                                                                           
ruff: FAIL ✖ in 4.6 seconds   
logston commented 4 months ago

Please also add your changes to the changelog: https://github.com/15five/scim2-filter-parser/blob/master/CHANGELOG.rst

JPDSousa commented 4 months ago

Please also add your changes to the changelog: https://github.com/15five/scim2-filter-parser/blob/master/CHANGELOG.rst

I've bumped the version to 0.6.0, based on semver:

MINOR version when you add functionality in a backward compatible manner

LMK if I should instead to a patch bump 👍