Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function call error handling #44

Open
mikeoverjet opened this issue Apr 27, 2022 · 1 comment
Open

function call error handling #44

mikeoverjet opened this issue Apr 27, 2022 · 1 comment

Comments

@mikeoverjet
Copy link

I tried to dig into the code and find some breadcrumbs but I couldn't get anywhere...

import sqlvalidator

query = 'SELECT * FROM table WHERE cast(start_time as date) > dateadd(year,-3,now());'
sql_query = sqlvalidator.parse(query)
sql_query.is_valid()

raises:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/sql_validator.py", line 25, in is_valid
    self._validate()
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/sql_validator.py", line 31, in _validate
    self.errors = self.sql_query.validate()
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/grammar/sql.py", line 137, in validate
    errors += self.where_clause.validate(known_fields)
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/grammar/sql.py", line 272, in validate
    errors += self.value.validate(known_fields)
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/grammar/sql.py", line 1439, in validate
    errors += self.value.validate(known_fields)
  File ".../python-3.9.4/lib/python3.9/site-packages/sqlvalidator/grammar/sql.py", line 557, in validate
    errors += a.validate(known_fields)
AttributeError: 'str' object has no attribute 'validate'
@timon-schmelzer-gcx
Copy link

Hi, I am facing the same issue, guessing that this is connected to the usage of CAST. Here is another example:

query = "SELECT CAST(X AS LONG) FROM table;"
res = sqlvalidator.parse(query)
res.is_valid()

File .../lib/python3.10/site-packages/sqlvalidator/sql_validator.py:25, in SQLQuery.is_valid(self)
     23 def is_valid(self) -> bool:
     24     if not self.validated:
---> 25         self._validate()
     26     return len(self.errors) == 0

File .../lib/python3.10/site-packages/sqlvalidator/sql_validator.py:31, in SQLQuery._validate(self)
     29 self.validated = True
     30 try:
---> 31     self.errors = self.sql_query.validate()
     32 except ParsingError as ex:
     33     self.errors.append(str(ex))

File .../lib/python3.10/site-packages/sqlvalidator/grammar/sql.py:133, in SelectStatement.validate(self, known_fields)
    130     known_fields = known_fields | self.from_statement.known_fields
    132 for e in self.expressions:
--> 133     errors += e.validate(known_fields)
    134 if self.from_statement:
    135     errors += self.from_statement.validate(known_fields=set())

File .../lib/python3.10/site-packages/sqlvalidator/grammar/sql.py:557, in FunctionCall.validate(self, known_fields)
    555 errors = super().validate(known_fields)
    556 for a in self.args:
--> 557     errors += a.validate(known_fields)
    558 return errors

AttributeError: 'str' object has no attribute 'validate'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants