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

environment-to-ini tracking bug #27541

Closed
n9 opened this issue Oct 9, 2023 · 8 comments · Fixed by #27543
Closed

environment-to-ini tracking bug #27541

n9 opened this issue Oct 9, 2023 · 8 comments · Fixed by #27543
Labels

Comments

@n9
Copy link

n9 commented Oct 9, 2023

Description

There are known issues with environment-to-ini: https://gitea.com/gitea/helm-chart/issues/356

However, I have not found an issue this repo, where the implementation of environment-to-ini is located.

Gitea Version

1.20.5

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Currently, the issue only occurs when environment-to-ini is explicitly used.

However, @silverwind mentioned in #24804 (comment) that there is an intention to merge enviornment-to-ini into the codebase. (I am not sure, whether this may cause then also issues in other deployments.)

Database

None

Further notes

In my case, the issue occurs during the configuration of "custom logger modes":

Failed to load writer mode "router" for logger router: invalid log writer type (mode): router, maybe it needs something like 'MODE=file' in [log.router] section
Failed to load writer mode "xorm" for logger xorm: invalid log writer type (mode): xorm, maybe it needs something like 'MODE=file' in [log.xorm] section

This is because environment-to-ini is unable to write [log.router] MODE=console to app.ini, as it is a default value.

(In this case, however, I am not sure what should be fixed, whether the environment-to-ini or "custom logger modes".)

@wxiaoguang
Copy link
Contributor

It was designed so. environment-to-ini only adds/updates, never deletes.

@wxiaoguang wxiaoguang added the issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea label Oct 9, 2023
@n9
Copy link
Author

n9 commented Oct 9, 2023

@wxiaoguang This is not about deletes, but is about "adds".

@n9
Copy link
Author

n9 commented Oct 9, 2023

Try to run environment-to-ini with e.g.

GITEA__log_0X2E_router__MODE=console
GITEA__log_0X2E_xorm__MODE=console

These values will not be added to app.ini if the [log] has MODE already set to console in the app.ini file.

n9 pushed a commit to n9/gitea that referenced this issue Oct 9, 2023
@n9
Copy link
Author

n9 commented Oct 9, 2023

I have added a failing test to demonstrate the issue: n9@c708961

@wxiaoguang
Copy link
Contributor

It's the legacy/unmaintained INI package's bug (or quirk behavior).

The section values are inherited. So [sec].key=SOME also means [sec.sub].key=SOME

@n9
Copy link
Author

n9 commented Oct 9, 2023

Yes, but this does not work in loadLogModeByName and fails here:

return "", "", writerMode, fmt.Errorf("invalid log writer type (mode): %s, maybe it needs something like 'MODE=file' in [log.%s] section", writerType, modeName)

As mode is resolved using ConfigSectionKeyString:

writerType = ConfigSectionKeyString(sec, "MODE")

which calls ConfigSectionString that is not using inheritance:

// ConfigInheritedKey works like ini.Section.Key(), but it always returns a new key instance, it is O(n) because NewKey is O(n)
// and the returned key is safe to be used with "MustXxx", it doesn't change the parent's values.
// Otherwise, ini.Section.Key().MustXxx would pollute the parent section's keys.
// It never returns nil.
func ConfigInheritedKey(sec ConfigSection, key string) ConfigKey {
k := sec.Key(key)
if k != nil && k.String() != "" {
newKey, _ := sec.NewKey(k.Name(), k.String())
return newKey
}
newKey, _ := sec.NewKey(key, "")
return newKey
}

@wxiaoguang
Copy link
Contributor

Thank you for your detailed report.

I think the fix could be this: Fix environment-to-ini inherited key bug #27543

@wxiaoguang wxiaoguang added type/bug and removed issue/not-a-bug The reported issue is the intended behavior or the problem is not inside Gitea labels Oct 9, 2023
@n9
Copy link
Author

n9 commented Oct 9, 2023

Thank you for the fix.

wxiaoguang added a commit that referenced this issue Oct 9, 2023
Fix  #27541

The INI package has a quirk: by default, the keys are inherited.
When maintaining the keys, the newly added sub key should not be
affected by the parent key.
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Oct 9, 2023
Fix  go-gitea#27541

The INI package has a quirk: by default, the keys are inherited.
When maintaining the keys, the newly added sub key should not be
affected by the parent key.
wxiaoguang added a commit that referenced this issue Oct 9, 2023
Backport #27543 by @wxiaoguang

Fix  #27541

The INI package has a quirk: by default, the keys are inherited.
When maintaining the keys, the newly added sub key should not be
affected by the parent key.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants