File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,11 @@ def query_type(self) -> str:
122122 switch = tokens [index ].normalized
123123 self ._query_type = SUPPORTED_QUERY_TYPES .get (switch , "UNSUPPORTED" )
124124 if self ._query_type == "UNSUPPORTED" :
125- self ._logger .error ("Not supported query type: %s" , self ._raw_query )
125+ # do not log the full query
126+ # https://github.com/macbre/sql-metadata/issues/543
127+ shorten_query = " " .join (self ._raw_query .split (" " )[:3 ])
128+
129+ self ._logger .error ("Not supported query type: %s" , shorten_query )
126130 raise ValueError ("Not supported query type!" )
127131 return self ._query_type
128132
Original file line number Diff line number Diff line change @@ -48,10 +48,10 @@ def test_drop_table_query():
4848 assert "DROP TABLE" == Parser (query .format (comment )).query_type
4949
5050
51- def test_unsupported_query ():
51+ def test_unsupported_query (caplog ):
5252 queries = [
53- "FOO BAR" ,
54- "DO SOMETHING" ,
53+ "FOO BAR LONG QUERY WITH MANY TOKENS " ,
54+ "DO SOMETHING LONG QUERY " ,
5555 ]
5656
5757 for query in queries :
@@ -60,6 +60,15 @@ def test_unsupported_query():
6060
6161 assert "Not supported query type!" in str (ex .value )
6262
63+ # assert the SQL query is not logged
64+ # https://docs.pytest.org/en/stable/how-to/logging.html#caplog-fixture
65+ assert (
66+ f"Not supported query type: { query } " not in caplog .text
67+ ), "The SQL query should not be logged"
68+ assert (
69+ f"Not supported query type: { query [:8 ]} " in caplog .text
70+ ), "The SQL query should be trimmed when logged"
71+
6372
6473def test_empty_query ():
6574 queries = ["" , "/* empty query */" ]
You can’t perform that action at this time.
0 commit comments