Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing env var prefix in documentation #2284

Closed
wants to merge 1 commit into from
Closed

Conversation

dekkers
Copy link
Contributor

@dekkers dekkers commented Jan 8, 2024

Changes

Currently the environment variables in the documentation are wrong because they all miss the prefix. I think this is since we updated pydantic, pydantic-settings and settings-doc. I've fixed settings-doc to include the prefix, this PR changed settings-doc to my fork while we wait for the PR to be merged and a new version released to PyPI.


Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

@dekkers dekkers requested a review from a team as a code owner January 8, 2024 22:33
@dekkers dekkers self-assigned this Jan 8, 2024
Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a bit hesitant when it comes to including external hotfixes because of the obvious reasons (keeping stuff up to date, missing dependabot alerts, etc.), but I think this could work as a temporary solution until, as you mentioned, this modification gets approved and merged in the designated package.

I was also wondering and currently still looking into this if it's possible to achieve this with the template (as it worked before?), but you've probably already looked into that.

Also, does this work for aliased fields? For example, the scheduler has a DEBUG variable, but based on the submitted PR I can infer that this would always produce prefixed fields like SCHEDULER_DEBUG and I'm not sure if that's correct and also loaded by pydantic-settings as the expected environment variable.

@ammar92
Copy link
Contributor

ammar92 commented Jan 9, 2024

I was also wondering and currently still looking into this if it's possible to achieve this with the template (as it worked before?), but you've probably already looked into that.

After some reading and experimenting, I found out we can reach the model_config.env_prefix attribute using the classes context variable in the template. With some effort we might be able to produce the same using only template code.

@dekkers
Copy link
Contributor Author

dekkers commented Jan 10, 2024

I'm still a bit hesitant when it comes to including external hotfixes because of the obvious reasons (keeping stuff up to date, missing dependabot alerts, etc.), but I think this could work as a temporary solution until, as you mentioned, this modification gets approved and merged in the designated package.

In my experience maintainers rarely release new versions without merging open PRs or giving feedback.

I was also wondering and currently still looking into this if it's possible to achieve this with the template (as it worked before?), but you've probably already looked into that.

I couldn't figure it out quickly. Given that the env_prefix is part of pydantic-settings, in my opinion settings-doc should also support that and it is the right place to fix this.

Also, does this work for aliased fields? For example, the scheduler has a DEBUG variable, but based on the submitted PR I can infer that this would always produce prefixed fields like SCHEDULER_DEBUG and I'm not sure if that's correct and also loaded by pydantic-settings as the expected environment variable.

This is not correct, when there is an alias the alias is used as before. There are also unit tests in settings-doc for this.

image

After some reading and experimenting, I found out we can reach the model_config.env_prefix attribute using the classes context variable in the template. With some effort we might be able to produce the same using only template code.

You would also need to make sure that aliased fields don't get the prefix. It might be possible, but it would also be double work, because there is already a fix for settings-doc. And while we are dicussing this, everybody who goes to OpenKAT documentation gets the wrong information and potentially wastes a lot of time before figuring out that our documentation is currently just plain wrong.

@dekkers
Copy link
Contributor Author

dekkers commented Jan 10, 2024

I forgot to mention the PR I opened, but it is radeklat/settings-doc#29

@ammar92
Copy link
Contributor

ammar92 commented Jan 10, 2024

In my experience maintainers rarely release new versions without merging open PRs or giving feedback.

While you might experience that, nothing indicates that this holds the same for this project, since the project doesn't have any real contributors expect for the owner (see issues and PRs).

I couldn't figure it out quickly. Given that the env_prefix is part of pydantic-settings, in my opinion settings-doc should also support that and it is the right place to fix this.

Agree, this should be part of settings-docs. But it isn't part of it yet, and maybe never will be. While with the templates it can already be achieved.

You would also need to make sure that aliased fields don't get the prefix. It might be possible, but it would also be double work, because there is already a fix for settings-doc.

Shouldn't be too hard to apply conditional formatting in Jinja templates: {% if field.alias %}{{ field.alias }}{% else %}{{ prefix }}{{ env_var }}{% endif %}

And while we are dicussing this, everybody who goes to OpenKAT documentation gets the wrong information and potentially wastes a lot of time before figuring out that our documentation is currently just plain wrong.

Agree, therefore we should quickly do something. Ultimately it comes down to whether we want a "corrupted" dependency tree or simply to use the template. I'll leave it up to you and @underdarknl

@dekkers dekkers deleted the fix-env-vars-docs branch June 25, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants