Skip to content

[Bug] grass.app.runtime.RuntimePaths default value is dangerous and leaks into rendered docs #6089

@echoix

Description

@echoix

Describe the bug

The __init__ of class grass.app.runtime.RuntimePaths uses a dangerous default value, and it is already flagged by Pylint W0102. They also leak in the generated docs.

class RuntimePaths:
"""Get runtime paths to resources and basic GRASS build properties
The resource paths are also set as environmental variables.
"""
def __init__(self, env=os.environ):
self.env = env

This mutable default value behavior was the first real Python problem that bit me years and years ago, and made me interested on how Python works. It is easy to get affected and not understand why things don't work.
That pylint warning is not enforced yet, as we have tons of places where we use an empty list for example. See the Pylint W0102 docs to understand the effect and the kind of fix needed.

The dangerous part here for us is that the contents of the env vars are reproduced in the rendered html docs, and change for each run.
We were lucky the env var GITHUB_TOKEN or other more sensitive info didn't show up in the published docs, as shown in the screenshots below.
There's also the problem of systematically have differences in the content, even if unchanged.

To reproduce

  1. Generate sphinx docs or download the mkdocs-site artifact of any documentation.yml workflow.
  2. Go to the docs for grass.app.runtime.RuntimePaths, or the published https://grass.osgeo.org/grass-devel/manuals/libpython/grass.app.html#grass.app.runtime.RuntimePaths
  3. See leaked env vars in docstring

Expected behavior

The environment vars are not leaked systematically

Screenshots

Image

Always different values:

Image

System description

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    PythonRelated code is in PythonbugSomething isn't workingdocs

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions