1616import os
1717import uuid
1818from pathlib import Path
19- from typing import TYPE_CHECKING , Any , Dict , Optional , cast
19+ from typing import TYPE_CHECKING , Any , Dict , Literal , Optional , cast , overload
2020from uuid import UUID
2121
2222from packaging import version
@@ -488,9 +488,25 @@ def get_config_environment_vars(self) -> Dict[str, str]:
488488
489489 return environment_vars
490490
491- def _get_store_configuration (
492- self , baseline : Optional [StoreConfiguration ] = None
493- ) -> StoreConfiguration :
491+ @overload
492+ def get_store_configuration (
493+ self ,
494+ baseline : Optional [StoreConfiguration ] = ...,
495+ allow_default : Literal [True ] = ...,
496+ ) -> StoreConfiguration : ...
497+
498+ @overload
499+ def get_store_configuration (
500+ self ,
501+ baseline : Optional [StoreConfiguration ] = ...,
502+ allow_default : Literal [False ] = ...,
503+ ) -> Optional [StoreConfiguration ]: ...
504+
505+ def get_store_configuration (
506+ self ,
507+ baseline : Optional [StoreConfiguration ] = None ,
508+ allow_default : bool = True ,
509+ ) -> Optional [StoreConfiguration ]:
494510 """Get the store configuration.
495511
496512 This method computes a store configuration starting from a baseline and
@@ -504,9 +520,12 @@ def _get_store_configuration(
504520
505521 Args:
506522 baseline: Optional baseline store configuration to use.
523+ allow_default: Whether to fall back to the default store
524+ configuration if none is set.
507525
508526 Returns:
509- The store configuration.
527+ The store configuration or `None` if defaults are disallowed and no
528+ configuration is available.
510529 """
511530 from zenml .zen_stores .base_zen_store import BaseZenStore
512531
@@ -555,15 +574,20 @@ def _get_store_configuration(
555574 logger .debug (
556575 "Using environment variables to update store config"
557576 )
558- if not store :
577+ if not store and allow_default :
559578 store = self .get_default_store ()
560- store = store .model_copy (update = env_store_config , deep = True )
579+ if store :
580+ store = store .model_copy (
581+ update = env_store_config , deep = True
582+ )
561583
562584 # Step 2: Only after we've applied the environment variables, we
563585 # fallback to the default store if no store configuration is set. This
564586 # is to avoid importing the SQL store config in cases where a rest store
565587 # is configured with environment variables.
566588 if not store :
589+ if not allow_default :
590+ return None
567591 store = self .get_default_store ()
568592
569593 # Step 3: Replace or update the baseline secrets store configuration
@@ -631,7 +655,7 @@ def store_configuration(self) -> StoreConfiguration:
631655 # configuration from there and disregard the global configuration.
632656 if self ._zen_store is not None :
633657 return self ._zen_store .config
634- return self ._get_store_configuration ()
658+ return self .get_store_configuration ()
635659
636660 def get_default_store (self ) -> StoreConfiguration :
637661 """Get the default SQLite store configuration.
@@ -655,7 +679,7 @@ def set_default_store(self) -> None:
655679 default store.
656680 """
657681 # Apply the environment variables to the default store configuration
658- default_store_cfg = self ._get_store_configuration (
682+ default_store_cfg = self .get_store_configuration (
659683 baseline = self .get_default_store ()
660684 )
661685 self ._configure_store (default_store_cfg )
@@ -697,8 +721,10 @@ def set_store(
697721 constructor.
698722 """
699723 # Apply the environment variables to the custom store configuration
700- config = self ._get_store_configuration (baseline = config )
701- self ._configure_store (config , skip_default_registrations , ** kwargs )
724+ resolved_config = self .get_store_configuration (baseline = config )
725+ self ._configure_store (
726+ resolved_config , skip_default_registrations , ** kwargs
727+ )
702728 logger .info ("Updated the global store configuration." )
703729
704730 @property
0 commit comments