pgjones / flake8-sql

Flake8 plugin that checks SQL code against opinionated style rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError NoneType - int

John-P opened this issue · comments

Running flake8 with flake8-sql on pre-commit CI is giving me the following error:

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 687, in _run_checks
    return checker.run_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 597, in run_checks
    self.run_ast_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 500, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8_sql/linter.py", line 49, in run
    initial_offset = _get_initial_offset(node, self.lines)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8_sql/linter.py", line 178, in _get_initial_offset
    first_physical_line = physical_lines[query_end_lineno - len(logical_lines)]
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 375, in run
    self._run(argv)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 364, in _run
    self.run_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 271, in run_checks
    self.file_checker_manager.run()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 309, in run
    self.run_parallel()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 275, in run_parallel
    for ret in pool_map:
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 448, in <genexpr>
    return (item for chunk in result for item in chunk)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 870, in next
    raise value
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

It appears that the problem is on this line:

first_physical_line = physical_lines[query_end_lineno - len(logical_lines)]

where the result of _get_query_end_lineno may be None.

Just noticed that this may be fixed by #21