Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Conversation

@mart-r
Copy link
Collaborator

@mart-r mart-r commented Jun 20, 2025

The medcat.utils.envsnapshot.get_environment_info method was called to find the default value for Config.meta.saved_environ at import time.
However, this can be problematic if/when the environment isn't completely loaded at import time.

So this PR does the following:

  • Sets the ModelMeta.saved_environ field a Field with a default_factory
    • This works because pydantic then calls the factory lazily only when needed
  • Makes the Config.meta field a Field with a default_factory
    • Otherwise the ModelMeta class was initialised and the method called at import time anyway
  • Adds a simple test to make sure the method isn't called at import time
    • This needed to use a subprocess because otherwise the module may already have been imported
    • And if that's the case the test would always pass

mart-r added 3 commits June 20, 2025 15:31
The new value is a default factory, which should be called lazily by pydantic instead of at import time.
This will avoid import time initialisation and subsequent call to environment info.
@mart-r mart-r changed the title CU-8699gfb13 Environment info calculation at impor time CU-8699gfb13 Environment info calculation at import time Jun 20, 2025
@mart-r mart-r merged commit adeabc9 into main Jun 20, 2025
4 checks passed
mart-r added a commit that referenced this pull request Jun 20, 2025
* CU-8699gfb13: Update the default value for environment in config.

The new value is a default factory, which should be called lazily by pydantic instead of at import time.

* CU-8699gfb13: Update config meta data default value.

This will avoid import time initialisation and subsequent call to environment info.

* CU-8699gfb13: Add a simple test to make sure the environmental info method isn't called at import time
alhendrickson pushed a commit to CogStack/cogstack-nlp that referenced this pull request Jun 24, 2025
…dCAT2#93)

* CU-8699gfb13: Update the default value for environment in config.

The new value is a default factory, which should be called lazily by pydantic instead of at import time.

* CU-8699gfb13: Update config meta data default value.

This will avoid import time initialisation and subsequent call to environment info.

* CU-8699gfb13: Add a simple test to make sure the environmental info method isn't called at import time
alhendrickson pushed a commit to CogStack/cogstack-nlp that referenced this pull request Jun 24, 2025
…dCAT2#93)

* CU-8699gfb13: Update the default value for environment in config.

The new value is a default factory, which should be called lazily by pydantic instead of at import time.

* CU-8699gfb13: Update config meta data default value.

This will avoid import time initialisation and subsequent call to environment info.

* CU-8699gfb13: Add a simple test to make sure the environmental info method isn't called at import time
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants