LLM-Engineers-Handbook icon indicating copy to clipboard operation
LLM-Engineers-Handbook copied to clipboard

settings in export works by accident because of the global settings variable.

Open amitmeel opened this issue 10 months ago • 2 comments

Current code is incorrect because it references settings in export() without ensuring it exists at the instance level or it exists as an instance attribute. However, it works due to the accidental global usage of settings at the bottom of the file.

### llm_engineering/settings.py
    def export(self) -> None:
        """
        Exports the settings to the ZenML secret store.
        """

        env_vars = settings.model_dump()
        for key, value in env_vars.items():
            env_vars[key] = str(value)

        client = Client()

        try:
            client.create_secret(name="settings", values=env_vars)
        except EntityExistsError:
            logger.warning(
                "Secret 'scope' already exists. Delete it manually by running 'zenml secret delete settings', before trying to recreate it."
            )


settings = Settings.load_settings()

This creates a global variable settings, containing an instance of Settings.This only works because the global settings exists.

Why is This Problematic? If settings = Settings.load_settings() is removed or not initialized yet, export() will fail.

isn't it better to use like this:

def export(self) -> None:
    env_vars = self.model_dump()  # ✅ Uses the instance properly and No hidden dependencies on a globally initialized settings.

or we can explicitly pass settings to export.

Just wanted to know why this was used this way since this is a wrong practice.

amitmeel avatar Feb 04 '25 09:02 amitmeel

please let me know if I should submit a PR to fix this.

amitmeel avatar Feb 04 '25 10:02 amitmeel

Hello @amitmeel ,

Yes, you are right.

This is a sneaky bug.

iusztinpaul avatar Mar 17 '25 11:03 iusztinpaul