You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying any of the above throws an error because our parser thinks it's SQL code. Instead, we should provide a more informative error:
"object.property" is not a valid connection identifier. Please pass the variable's name directly, as passing object attributes, dictionaries `some_dict[key]` or lists `some_list[0]` won't work. Example: `%sql connection`
so we need a way to identity such cases, we can use the following heuristics:
the magic gets a single argument (no spaces between characters) - because valid SQL code will always have spaces
we can check if the argument is not a valid identifier using argument.isidentifier() but it is valid Python code (using ast.parse)
if those conditions hold, then we can raise the error.
The text was updated successfully, but these errors were encountered:
edublancas
changed the title
improve error message
improve error message when passing a non-identifier to start a connection
Jul 27, 2023
Raise a more informative error when a connection object that is a part of object, dictionary, or list (eg. %sql object.property, %sql dictionary["key"], %sql some_list[0]) is passed
a. error example :
"object.property" is not a valid connection identifier. Please pass the variable's name directly, as passing object attributes, dictionaries `some_dict[key]` or lists `some_list[0]` won't work. Example: `%sql connection`
we allow users to pass a connection variable to connect to a db. example:
however, in some cases, the connection object might be part of a dictionary, list or object. examples:
Trying any of the above throws an error because our parser thinks it's SQL code. Instead, we should provide a more informative error:
so we need a way to identity such cases, we can use the following heuristics:
argument.isidentifier()
but it is valid Python code (using ast.parse)if those conditions hold, then we can raise the error.
The text was updated successfully, but these errors were encountered: