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

StrConfigItem returns None instead of 'none' if os.environ is modified #921

Open
braingram opened this issue Feb 6, 2023 · 0 comments
Open

Comments

@braingram
Copy link
Contributor

braingram commented Feb 6, 2023

This issue arose while attempting to get stdatamodels tests to run locally (fix and semi-related discussion in: spacetelescope/stdatamodels#117).

A set of tests including a local import of crds always failed after the first call. This was traced back to a use of CRDS_REFERENCE_URI that returned None instead of 'none'. Here's a reproducer:

import os
import pytest

@pytest.fixture
def jail_environ():
    """Lock changes to the environment"""
    original = os.environ.copy()
    try:
        yield
    finally:
        os.environ = original

@pytest.mark.parametrize('value', ['1', '2'])
def test_crds(jail_environ, value):
    import crds
    assert crds.core.config.CRDS_REFERENCE_URI.get() == 'none'

If the import crds is moved outside the test (and no longer 'jailed' by the fixture) the tests pass without issue.

I'm not certain if this is a crds bug as crds might assume that the environment variables are unchanged between calls. A minimal reproducer (without pytest is):

import os
import crds

assert crds.core.config.CRDS_REFERENCE_URI.get() == 'none'
del os.environ['CRDS_REFERENCE_URI']
assert crds.core.config.CRDS_REFERENCE_URI.get() is None

The 'issue' isn't seen with an unmodified environment because the first call to StrConfigItem.get occurs within StrConfigItem.__init__ and the return value is thrown away. This call also sets the environment variable so future calls to StrConfigItem.get return the expected 'none'.

self.get()

I think the issue could be addressed by changing these None values to 'none' (but am not familiar with the inner workings of CRDS to predict any knock-on effects).

crds/crds/core/config.py

Lines 735 to 749 in 4b19990

CRDS_CONFIG_URI = StrConfigItem("CRDS_CONFIG_URI", None,
"Defines the URL/URI from which CRDS config files are downloaded.",
lower=True)
CRDS_MAPPING_URI = StrConfigItem("CRDS_MAPPING_URI", None,
"Defines the URL/URI from which CRDS mapping files are downloaded.",
lower=True)
CRDS_REFERENCE_URI = StrConfigItem("CRDS_REFERENCE_URI", None,
"Defines the URL/URI from which CRDS reference files are downloaded.",
lower=True)
CRDS_PICKLE_URI = StrConfigItem("CRDS_PICKLE_URI", None,
"Defines the URL/URI from which CRDS pickle files are downloaded.",
lower=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant