Whole file
David-Wobrock/sqlvalidator
The author described this change as “Fix validating between predicate conditions”. It counts as a record because the check below fails on the code as it stood at 362ec80af and passes on a3bf4fcc6, with nothing else changed between the two runs.
ProjectDavid-Wobrock/sqlvalidator
Fix saved2021-11-15
Sharing licenceMIT · LICENSE
Change size+12 −8
What the code was meant to do, written into the code itself as a save note
Fix validating between predicate conditions
The change
| 1437 | 1437 | def validate(self, known_fields): | |
| 1438 | 1438 | errors = super().validate(known_fields) | |
| 1439 | 1439 | errors += self.value.validate(known_fields) | |
| 1440 | - | errors += self.right_hand.validate(known_fields) | |
| 1440 | + | if self.predicate.lower() == "between": | |
| 1441 | + | errors += self.right_hand.validate(known_fields, is_between_predicate=True) | |
| 1442 | + | else: | |
| 1443 | + | errors += self.right_hand.validate(known_fields) | |
| 1441 | 1444 | return errors | |
| 1442 | 1445 | ||
| 1443 | 1446 | @property | |
| ⋯ | |||
| 1489 | 1492 | and all(a == o for a, o in zip(self.args, other.args)) | |
| 1490 | 1493 | ) | |
| 1491 | 1494 | ||
| 1492 | - | def validate(self, known_fields): | |
| 1495 | + | def validate(self, known_fields, is_between_predicate=False): | |
| 1493 | 1496 | errors = super().validate(known_fields) | |
| 1494 | 1497 | for a in self.args: | |
| 1495 | 1498 | errors += a.validate(known_fields) | |
| 1496 | - | a_type = a.resolve_return_type(known_fields) | |
| 1497 | - | if a_type not in (bool, Any): | |
| 1498 | - | errors.append( | |
| 1499 | - | "The argument of {} must be type boolean, not type {}".format( | |
| 1500 | - | self.type.upper(), a_type.__name__ | |
| 1499 | + | if not is_between_predicate: | |
| 1500 | + | a_type = a.resolve_return_type(known_fields) | |
| 1501 | + | if a_type not in (bool, Any): | |
| 1502 | + | errors.append( | |
| 1503 | + | "The argument of {} must be type boolean, not type {}".format( | |
| 1504 | + | self.type.upper(), a_type.__name__ | |
| 1505 | + | ) | |
| 1501 | 1506 | ) | |
| 1502 | - | ) | |
| 1503 | 1507 | ||
| 1504 | 1508 | return errors | |
| 1505 | 1509 | ||
The check that tells the two apart
fail→pass·tests/integration/test_validation.py::test_between_condition_is_valid
Check file tests/integration/test_validation.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it362ec80af081a4fe9710832060e8f2f89d545cd2
Broken version dated2021-11-15
Modulesqlvalidator.grammar.sql
Units changedBooleanCondition, Condition
Fingerprint73c5e56ffa60f291
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in David-Wobrock/sqlvalidator
- 2022-04-15Fix #38 -- Handle nested case expressions
- 2021-12-22Fix #29 -- Handle strings containing others quotes
- 2021-12-22Fix #35 -- Handle index based access on function call
- 2021-12-22Fix #34 -- Handle parsing a function with a single comma string
- 2021-11-15Fix handling Any return type as invalid WHERE/HAVING condition
- 2021-11-14Fix Alias.known_fields for aliased subqueries with specific fields