Closed kumy closed 2 hours ago
@kumy the helper functions aren't covered by unit tests at the moment, but since we normally only use exists()
to validate if a container exists, your suggested change should be safe. If you open a PR I'll merge it.
@AdSchellevis please find PR #7918
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
Describe the bug
While working a new template for a plugin I'm working on, I went to the
helpers.exists()
function. Given the function name and the docstring, we should expect this function to return aboolean
. But this returns astring
, which is technically incorrect. This cause issue with existing node path with empty values.https://github.com/opnsense/core/blob/66e62f4a899c5847faf47427f6670077103c1de7/src/opnsense/service/modules/addons/template_helpers.py#L76-L82
To Reproduce (rough untested steps - sorry)
Steps to reproduce the behavior:
{{ helpers.exists('path.to.some.existing.node') }}
and{{ helpers.exists('path.to.some.non.existing.node') }}
config.xml
set the pathpath.to.some.existing.node
to "empty string".Expected behavior
{{ helpers.exists('path.to.some.existing.node) }}
should return booleanTrue
. It actually returns the stringNone
.{{ helpers.exists('path.to.some.non.existing.node) }}
should return booleanFalse
. It actually returns the stringNone
.Describe alternatives you considered The working alternative code is
helpers.exists(conf ~ '.' ~ path) != 'None'
Some tests.
With an empty value: (
system.backup.restic.repositories.minio.advanced.http_user_agent
is empty string in config.xml)With a non empty value: (
system.backup.restic.general.advanced.http_user_agent
is non-empty string in config.xml)And when the value is really the string
None
(with is not an empty value)Fixing proposal
This could be a way to fix it:
With this patch we get:
And when the value is really the string
None
(with is not an empty value)Additional context
Will it break existing uses? :shrug:
Is there any existing unit test for this method?