Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sql_metadata/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ def query_type(self) -> str:
switch = tokens[index].normalized
self._query_type = SUPPORTED_QUERY_TYPES.get(switch, "UNSUPPORTED")
if self._query_type == "UNSUPPORTED":
self._logger.error("Not supported query type: %s", self._raw_query)
# do not log the full query
# https://github.com/macbre/sql-metadata/issues/543
shorten_query = " ".join(self._raw_query.split(" ")[:3])

self._logger.error("Not supported query type: %s", shorten_query)
raise ValueError("Not supported query type!")
return self._query_type

Expand Down
15 changes: 12 additions & 3 deletions test/test_query_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def test_drop_table_query():
assert "DROP TABLE" == Parser(query.format(comment)).query_type


def test_unsupported_query():
def test_unsupported_query(caplog):
queries = [
"FOO BAR",
"DO SOMETHING",
"FOO BAR LONG QUERY WITH MANY TOKENS",
"DO SOMETHING LONG QUERY",
]

for query in queries:
Expand All @@ -60,6 +60,15 @@ def test_unsupported_query():

assert "Not supported query type!" in str(ex.value)

# assert the SQL query is not logged
# https://docs.pytest.org/en/stable/how-to/logging.html#caplog-fixture
assert (
f"Not supported query type: {query}" not in caplog.text
), "The SQL query should not be logged"
assert (
f"Not supported query type: {query[:8]}" in caplog.text
), "The SQL query should be trimmed when logged"


def test_empty_query():
queries = ["", "/* empty query */"]
Expand Down