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

ValueError: No closing quotation / Likely argument parsing issue. #954

Open
dmcmurchy opened this issue Nov 30, 2023 · 2 comments
Open

ValueError: No closing quotation / Likely argument parsing issue. #954

dmcmurchy opened this issue Nov 30, 2023 · 2 comments

Comments

@dmcmurchy
Copy link

What happens?

Executing:

%sql SELECT TRIM(' padded ');

Produces a ValueError:

----> 1 get_ipython().run_line_magic('sql', "SELECT TRIM(' padded ');")

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\IPython\core\interactiveshell.py:2432, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2430     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2431 with self.builtin_trap:
-> 2432     result = fn(*args, **kwargs)
   2434 # The code below prevents the output from being displayed
   2435 # when using magics with decorator @output_can_be_silenced
   2436 # when the last Python token in the expression is a ';'.
   2437 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\sql\magic.py:360, in SqlMagic.execute(self, line, cell, local_ns)
    252 @no_var_expand
    253 @needs_local_scope
    254 @line_magic("sql")
   (...)
    332 )
    333 def execute(self, line="", cell="", local_ns=None):
    334     """
    335     Runs SQL statement against a database, specified by
    336     SQLAlchemy connect string.
   (...)
    358 
    359     """
--> 360     return self._execute(
    361         line=line, cell=cell, local_ns=local_ns, is_interactive_mode=False
    362     )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\ploomber_core\telemetry\telemetry.py:640, in Telemetry.log_call.<locals>._log_call.<locals>.wrapper(*args, **kwargs)
    638     injected_args = list(args)
    639     injected_args.insert(1, _payload)
--> 640     result = func(*injected_args, **kwargs)
    641 else:
    642     result = func(_payload, *args, **kwargs)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\ploomber_core\exceptions.py:111, in modify_exceptions.<locals>.wrapper(*args, **kwargs)
    108 @wraps(fn)
    109 def wrapper(*args, **kwargs):
    110     try:
--> 111         return fn(*args, **kwargs)
    112     except (ValueError, TypeError) as e:
    113         _add_community_link(e)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\sql\magic.py:398, in SqlMagic._execute(self, payload, line, cell, local_ns, is_interactive_mode)
    395 user_ns = self.shell.user_ns.copy()
    396 user_ns.update(local_ns)
--> 398 command = SQLCommand(self, user_ns, line, cell)
    399 # args.line: contains the line after the magic with all options removed
    401 args = command.args

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\sql\command.py:29, in SQLCommand.__init__(self, magic, user_ns, line, cell)
     26 self._line = line
     27 self._cell = cell
---> 29 self.args = parse.magic_args(
     30     magic.execute,
     31     line,
     32     "sql",
     33     allowed_duplicates=["-w", "--with", "--append", "--interact"],
     34 )
     36 # self.args.line (everything that appears after %sql/%%sql in the first line)
     37 # is split in tokens (delimited by spaces), this checks if we have one arg
     38 one_arg = len(self.args.line) == 1

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\sql\parse.py:287, in magic_args(magic_execute, line, cmd_from, allowed_duplicates)
    283 """
    284 Returns the parsed arguments from the line as parsed by magic_execute
    285 """
    286 allowed_duplicates = allowed_duplicates or []
--> 287 line = without_sql_comment(parser=magic_execute.parser, line=line)
    288 arg_line, sql_line = split_args_and_sql(line)
    290 args = shlex.split(arg_line, posix=False)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\sql\parse.py:233, in without_sql_comment(parser, line)
    220 """Strips -- comment from a line
    221 
    222 The argparser unfortunately expects -- to precede an option,
   (...)
    227 :type line: str
    228 """
    230 args = _option_strings_from_parser(parser)
    231 result = itertools.takewhile(
    232     lambda word: (not word.startswith("--")) or (word in args),
--> 233     shlex.split(line, posix=False),
    234 )
    235 return " ".join(result)

File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\shlex.py:315, in split(s, comments, posix)
    313 if not comments:
    314     lex.commenters = ''
--> 315 return list(lex)

File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\shlex.py:300, in shlex.__next__(self)
    299 def __next__(self):
--> 300     token = self.get_token()
    301     if token == self.eof:
    302         raise StopIteration

File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\shlex.py:109, in shlex.get_token(self)
    107     return tok
    108 # No pushback.  Get a token.
--> 109 raw = self.read_token()
    110 # Handle inclusions
    111 if self.source is not None:

File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\shlex.py:191, in shlex.read_token(self)
    189         print("shlex: I see EOF in quotes state")
    190     # XXX what error should be raised here?
--> 191     raise ValueError("No closing quotation")
    192 if nextchar == self.state:
    193     if not self.posix:

ValueError: No closing quotation

Executing with:

%%sql
SELECT TRIM(' padded ');

Produces the expected result:

btrim
padded

To Reproduce

%sql SELECT TRIM(' padded ');

OS:

Windows 11

JupySQL Version:

0.10.5.dev0,

Full Name:

Dwayne McMurchy

Affiliation:

n/a

@edublancas
Copy link

thanks for reporting this! I believe this was introduced in version 0.10.4, when we added validation for repeated arguments

@nooodle-soup can you check this?

@fenrir-san
Copy link

@edublancas On it!

@fenrir-san fenrir-san mentioned this issue Dec 4, 2023
3 tasks
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

Successfully merging a pull request may close this issue.

3 participants