@@ -150,9 +150,6 @@ def get_session():
150150
151151
152152class AtlanClient (BaseSettings ):
153- _current_client_ctx : ClassVar [ContextVar ] = ContextVar (
154- "_current_client_ctx" , default = None
155- )
156153 _401_has_retried_ctx : ClassVar [ContextVar ] = ContextVar (
157154 "_401_has_retried_ctx" , default = False
158155 )
@@ -195,25 +192,6 @@ class AtlanClient(BaseSettings):
195192 class Config :
196193 env_prefix = "atlan_"
197194
198- @classmethod
199- def set_current_client (cls , client : AtlanClient ):
200- """
201- Sets the current client context
202- """
203- if not isinstance (client , AtlanClient ):
204- raise ErrorCode .MISSING_ATLAN_CLIENT .exception_with_parameters ()
205- cls ._current_client_ctx .set (client )
206-
207- @classmethod
208- def get_current_client (cls ) -> AtlanClient :
209- """
210- Retrieves the current client context
211- """
212- client = cls ._current_client_ctx .get ()
213- if not client :
214- raise ErrorCode .NO_ATLAN_CLIENT_AVAILABLE .exception_with_parameters ()
215- return client
216-
217195 def __init__ (self , ** data ):
218196 super ().__init__ (** data )
219197 self ._request_params = {
@@ -225,188 +203,161 @@ def __init__(self, **data):
225203 adapter = HTTPAdapter (max_retries = self .retry )
226204 session .mount (HTTPS_PREFIX , adapter )
227205 session .mount (HTTP_PREFIX , adapter )
228- AtlanClient .set_current_client (self )
229206 self ._401_has_retried_ctx .set (False )
230207
231208 @property
232209 def admin (self ) -> AdminClient :
233210 if self ._admin_client is None :
234- AtlanClient .set_current_client (self )
235211 self ._admin_client = AdminClient (client = self )
236212 return self ._admin_client
237213
238214 @property
239215 def audit (self ) -> AuditClient :
240216 if self ._audit_client is None :
241- AtlanClient .set_current_client (self )
242217 self ._audit_client = AuditClient (client = self )
243218 return self ._audit_client
244219
245220 @property
246221 def search_log (self ) -> SearchLogClient :
247222 if self ._search_log_client is None :
248- AtlanClient .set_current_client (self )
249223 self ._search_log_client = SearchLogClient (client = self )
250224 return self ._search_log_client
251225
252226 @property
253227 def workflow (self ) -> WorkflowClient :
254228 if self ._workflow_client is None :
255- AtlanClient .set_current_client (self )
256229 self ._workflow_client = WorkflowClient (client = self )
257230 return self ._workflow_client
258231
259232 @property
260233 def credentials (self ) -> CredentialClient :
261234 if self ._credential_client is None :
262- AtlanClient .set_current_client (self )
263235 self ._credential_client = CredentialClient (client = self )
264236 return self ._credential_client
265237
266238 @property
267239 def group (self ) -> GroupClient :
268240 if self ._group_client is None :
269- AtlanClient .set_current_client (self )
270241 self ._group_client = GroupClient (client = self )
271242 return self ._group_client
272243
273244 @property
274245 def role (self ) -> RoleClient :
275246 if self ._role_client is None :
276- AtlanClient .set_current_client (self )
277247 self ._role_client = RoleClient (client = self )
278248 return self ._role_client
279249
280250 @property
281251 def asset (self ) -> AssetClient :
282252 if self ._asset_client is None :
283- AtlanClient .set_current_client (self )
284253 self ._asset_client = AssetClient (client = self )
285254 return self ._asset_client
286255
287256 @property
288257 def impersonate (self ) -> ImpersonationClient :
289258 if self ._impersonate_client is None :
290- AtlanClient .set_current_client (self )
291259 self ._impersonate_client = ImpersonationClient (client = self )
292260 return self ._impersonate_client
293261
294262 @property
295263 def queries (self ) -> QueryClient :
296264 if self ._query_client is None :
297- AtlanClient .set_current_client (self )
298265 self ._query_client = QueryClient (client = self )
299266 return self ._query_client
300267
301268 @property
302269 def token (self ) -> TokenClient :
303270 if self ._token_client is None :
304- AtlanClient .set_current_client (self )
305271 self ._token_client = TokenClient (client = self )
306272 return self ._token_client
307273
308274 @property
309275 def typedef (self ) -> TypeDefClient :
310276 if self ._typedef_client is None :
311- AtlanClient .set_current_client (self )
312277 self ._typedef_client = TypeDefClient (client = self )
313278 return self ._typedef_client
314279
315280 @property
316281 def user (self ) -> UserClient :
317282 if self ._user_client is None :
318- AtlanClient .set_current_client (self )
319283 self ._user_client = UserClient (client = self )
320284 return self ._user_client
321285
322286 @property
323287 def tasks (self ) -> TaskClient :
324288 if self ._task_client is None :
325- AtlanClient .set_current_client (self )
326289 self ._task_client = TaskClient (client = self )
327290 return self ._task_client
328291
329292 @property
330293 def sso (self ) -> SSOClient :
331294 if self ._sso_client is None :
332- AtlanClient .set_current_client (self )
333295 self ._sso_client = SSOClient (client = self )
334296 return self ._sso_client
335297
336298 @property
337299 def open_lineage (self ) -> OpenLineageClient :
338300 if self ._open_lineage_client is None :
339- AtlanClient .set_current_client (self )
340301 self ._open_lineage_client = OpenLineageClient (client = self )
341302 return self ._open_lineage_client
342303
343304 @property
344305 def files (self ) -> FileClient :
345306 if self ._file_client is None :
346- AtlanClient .set_current_client (self )
347307 self ._file_client = FileClient (client = self )
348308 return self ._file_client
349309
350310 @property
351311 def contracts (self ) -> ContractClient :
352312 if self ._contract_client is None :
353- AtlanClient .set_current_client (self )
354313 self ._contract_client = ContractClient (client = self )
355314 return self ._contract_client
356315
357316 @property
358317 def atlan_tag_cache (self ) -> AtlanTagCache :
359318 if self ._atlan_tag_cache is None :
360- AtlanClient .set_current_client (self )
361319 self ._atlan_tag_cache = AtlanTagCache (client = self )
362320 return self ._atlan_tag_cache
363321
364322 @property
365323 def enum_cache (self ) -> EnumCache :
366324 if self ._enum_cache is None :
367- AtlanClient .set_current_client (self )
368325 self ._enum_cache = EnumCache (client = self )
369326 return self ._enum_cache
370327
371328 @property
372329 def group_cache (self ) -> GroupCache :
373330 if self ._group_cache is None :
374- AtlanClient .set_current_client (self )
375331 self ._group_cache = GroupCache (client = self )
376332 return self ._group_cache
377333
378334 @property
379335 def role_cache (self ) -> RoleCache :
380336 if self ._role_cache is None :
381- AtlanClient .set_current_client (self )
382337 self ._role_cache = RoleCache (client = self )
383338 return self ._role_cache
384339
385340 @property
386341 def user_cache (self ) -> UserCache :
387342 if self ._user_cache is None :
388- AtlanClient .set_current_client (self )
389343 self ._user_cache = UserCache (client = self )
390344 return self ._user_cache
391345
392346 @property
393347 def custom_metadata_cache (self ) -> CustomMetadataCache :
394348 if self ._custom_metadata_cache is None :
395- AtlanClient .set_current_client (self )
396349 self ._custom_metadata_cache = CustomMetadataCache (client = self )
397350 return self ._custom_metadata_cache
398351
399352 @property
400353 def connection_cache (self ) -> ConnectionCache :
401354 if self ._connection_cache is None :
402- AtlanClient .set_current_client (self )
403355 self ._connection_cache = ConnectionCache (client = self )
404356 return self ._connection_cache
405357
406358 @property
407359 def source_tag_cache (self ) -> SourceTagCache :
408360 if self ._source_tag_cache is None :
409- AtlanClient .set_current_client (self )
410361 self ._source_tag_cache = SourceTagCache (client = self )
411362 return self ._source_tag_cache
412363
@@ -1845,31 +1796,29 @@ def max_retries(
18451796
18461797@contextlib .contextmanager
18471798def client_connection (
1799+ client : AtlanClient ,
18481800 base_url : Optional [HttpUrl ] = None ,
18491801 api_key : Optional [str ] = None ,
18501802 connect_timeout : float = 30.0 ,
18511803 read_timeout : float = 120.0 ,
18521804 retry : Retry = DEFAULT_RETRY ,
18531805) -> Generator [AtlanClient , None , None ]:
18541806 """
1855- Creates a new client created with the given base_url and/api_key. The AtlanClient.default_client will
1856- be set to the new client. AtlanClient.default_client will be reset to the current default_client before
1857- exiting the context.
1858- :param base_url: the base_url to be used for the new connection. If not specified the current value will be used
1859- :param api_key: the api_key to be used for the new connection. If not specified the current value will be used
1807+ Creates a new client created with the given base_url and/api_key.
1808+
1809+ :param base_url: the base_url to be used for the new connection.
1810+ If not specified the current value will be used
1811+ :param api_key: the api_key to be used for the new connection.
1812+ If not specified the current value will be used
18601813 """
1861- current_client = AtlanClient .get_current_client ()
18621814 tmp_client = AtlanClient (
1863- base_url = base_url or current_client .base_url ,
1864- api_key = api_key or current_client .api_key ,
1815+ base_url = base_url or client .base_url ,
1816+ api_key = api_key or client .api_key ,
18651817 connect_timeout = connect_timeout ,
18661818 read_timeout = read_timeout ,
18671819 retry = retry ,
18681820 )
1869- try :
1870- yield tmp_client
1871- finally :
1872- AtlanClient .set_current_client (current_client )
1821+ yield tmp_client
18731822
18741823
18751824from pyatlan .model .keycloak_events import ( # noqa: E402
0 commit comments