1515import collections
1616import os
1717import uuid
18+ import warnings
1819
1920import pytest
2021from absl .testing import absltest , parameterized
@@ -1803,14 +1804,20 @@ def test_get_nodes_by_filter_query(self, create_type_fn, put_type_fn,
18031804 nodes [i ].custom_properties ["p" ].int_value = i
18041805 node_ids = put_nodes_fn (store , nodes )
18051806
1806- got_nodes = get_nodes_fn (
1807- store ,
1808- list_options = mlmd .ListOptions (
1809- order_by = mlmd .OrderByField .ID ,
1810- is_asc = True ,
1811- filter_query = ("custom_properties.p.int_value < 21 AND "
1812- "name LIKE 'node_2%'" )
1813- ))
1807+ # Verify deprecation warning is raised when using filter_query
1808+ with self .assertWarns (DeprecationWarning ) as warning_context :
1809+ got_nodes = get_nodes_fn (
1810+ store ,
1811+ list_options = mlmd .ListOptions (
1812+ order_by = mlmd .OrderByField .ID ,
1813+ is_asc = True ,
1814+ filter_query = ("custom_properties.p.int_value < 21 AND "
1815+ "name LIKE 'node_2%'" )
1816+ ))
1817+ # Verify the warning message mentions version 1.18.0
1818+ self .assertIn ("1.18.0" , str (warning_context .warning ))
1819+ self .assertIn ("filter_query" , str (warning_context .warning ))
1820+
18141821 self .assertLen (got_nodes , 2 )
18151822 self .assertEqual (got_nodes [0 ].id , node_ids [2 ])
18161823 self .assertEqual (got_nodes [0 ].name , "node_2" )
@@ -1822,9 +1829,15 @@ def test_get_nodes_by_filter_query(self, create_type_fn, put_type_fn,
18221829 (mlmd .MetadataStore .get_contexts ))
18231830 def test_get_nodes_by_filter_query_syntax_errors (self , get_nodes_fn ):
18241831 store = _get_metadata_store (self .cli_args )
1825- with self .assertRaises (errors .InvalidArgumentError ):
1832+ # Verify deprecation warning is raised even for syntax errors
1833+ with (
1834+ self .assertWarns (DeprecationWarning ) as warning_context ,
1835+ self .assertRaises (errors .InvalidArgumentError ),
1836+ ):
18261837 _ = get_nodes_fn (
18271838 store , list_options = mlmd .ListOptions (filter_query = "invalid syntax" ))
1839+ # Verify the warning message mentions version 1.18.0
1840+ self .assertIn ("1.18.0" , str (warning_context .warning ))
18281841
18291842 def test_put_contexts_get_context_by_type_and_name (self ):
18301843 # Prepare test data.
@@ -2112,12 +2125,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21122125 # Test get_lineage_subgraph() with max_num_hops = 10 and field mask paths =
21132126 # ["events", "associations", "attributions"], the whole lineage subgraph
21142127 # skeleton will be returned.
2115- query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2116- starting_artifacts = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2117- filter_query = "uri = 'output_artifact'"
2118- ),
2119- max_num_hops = 10 ,
2120- )
2128+ # Note: filter_query is deprecated but tested here for backward compatibility.
2129+ with warnings .catch_warnings ():
2130+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
2131+ query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2132+ starting_artifacts = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2133+ filter_query = "uri = 'output_artifact'"
2134+ ),
2135+ max_num_hops = 10 ,
2136+ )
21212137
21222138 subgraph_skeleton = store .get_lineage_subgraph (
21232139 query_options , ["events" , "associations" , "attributions" ]
@@ -2169,12 +2185,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21692185
21702186 # Test get_lineage_subgraph() with max_num_hops = 0 from starting executions
21712187 # filtered by context name. All the executions will be returned.
2172- query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2173- starting_executions = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2174- filter_query = "contexts_a.name='existing_context'"
2175- ),
2176- max_num_hops = 0 ,
2177- )
2188+ # Note: filter_query is deprecated but tested here for backward compatibility.
2189+ with warnings .catch_warnings ():
2190+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
2191+ query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2192+ starting_executions = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2193+ filter_query = "contexts_a.name='existing_context'"
2194+ ),
2195+ max_num_hops = 0 ,
2196+ )
21782197 subgraph = store .get_lineage_subgraph (query_options )
21792198 self .assertEmpty (subgraph .artifacts )
21802199 self .assertLen (subgraph .executions , 2 )
@@ -2195,12 +2214,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21952214 self .assertEmpty (subgraph .attributions )
21962215
21972216 # Test get_lineage_subgraph() with various field mask paths.
2198- query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2199- starting_artifacts = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2200- filter_query = "uri = 'output_artifact'"
2201- ),
2202- max_num_hops = 10 ,
2203- )
2217+ # Note: filter_query is deprecated but tested here for backward compatibility.
2218+ with warnings .catch_warnings ():
2219+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
2220+ query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2221+ starting_artifacts = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2222+ filter_query = "uri = 'output_artifact'"
2223+ ),
2224+ max_num_hops = 10 ,
2225+ )
22042226
22052227 subgraph = store .get_lineage_subgraph (
22062228 query_options , ["artifact_types" , "execution_types" , "context_types" ]
@@ -2291,13 +2313,16 @@ def test_put_lineage_subgraph_get_lineage_subgraph_with_direction(self):
22912313 )
22922314
22932315 # Test get_lineage_subgraph() with direction.
2294- query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2295- starting_executions = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2296- filter_query = "name = 'test_execution'"
2297- ),
2298- max_num_hops = 2 ,
2299- direction = metadata_store_pb2 .LineageSubgraphQueryOptions .Direction .DOWNSTREAM ,
2300- )
2316+ # Note: filter_query is deprecated but tested here for backward compatibility.
2317+ with warnings .catch_warnings ():
2318+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
2319+ query_options = metadata_store_pb2 .LineageSubgraphQueryOptions (
2320+ starting_executions = metadata_store_pb2 .LineageSubgraphQueryOptions .StartingNodes (
2321+ filter_query = "name = 'test_execution'"
2322+ ),
2323+ max_num_hops = 2 ,
2324+ direction = metadata_store_pb2 .LineageSubgraphQueryOptions .Direction .DOWNSTREAM ,
2325+ )
23012326 subgraph = store .get_lineage_subgraph (query_options )
23022327 self .assertLen (subgraph .artifacts , 1 )
23032328 self .assertLen (subgraph .executions , 1 )
0 commit comments