You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
reload_config no longer properly reloads user-set values #18138
config.reload_config is meant to reset all user-defined configuration items, but no longer does in 7.1 (it works on 7.0).
It is related to #17461, which optimized getting config item values by storing them on the items themselves. Unfortunately, reload_config only clears the general storage, not these cached values.
Expected behavior
It should reload.
How to Reproduce
from astropy import config
from astropy.utils.data import conf
conf.remote_timeout
# 10.0
conf.remote_timeout = 5
config.reload_config()
conf.remote_timeout
# 5.0
conf.reload() # This does work
conf.remote_timeout
# 10.0
A fix is the following, but this is astropy specific, so not quite correct. It may be better to make value some kind of weakref link to the actual configuration. CC @saimn since the caching in #17461 is what is causing the problems.
git diff
diff --git a/astropy/config/configuration.py b/astropy/config/configuration.py
index 8b08f9c55d..3a57abf096 100644
--- a/astropy/config/configuration.py+++ b/astropy/config/configuration.py@@ -771,6 +771,16 @@ def reload_config(packageormod=None, rootname=None):
Name of the root configuration directory - see `get_config`
for details.
"""
+ sec = get_config(packageormod, False, rootname=rootname)+ # look for the section that is its own parent - that's the base object+ while sec.parent is not sec:+ sec = sec.parent+ # Reset any items explicitly set, to clear possible cached values.+ for modname, keys in sec.items():+ mod = importlib.import_module(f"astropy.{modname}")+ conf = getattr(mod, "conf", None)+ if conf is not None:+ conf.reload()
sec = get_config(packageormod, True, rootname=rootname)
# look for the section that is its own parent - that's the base object
while sec.parent is not sec:
I think this is a release blocker for astropy v7.1.0. We cannot ship a release with broken public API that affects config for downstream packages. Simplest is to revert #17461 unless someone has a better idea. And definitely need RC2 now after this is patched. What do you think @astropy/astropy-project-release-team ?
Also cc @Cadair since apparently he is very into subclassing config stuff downstream.
Darn! There are too many ways to do stuff with this config API...
We could do what @mhvk proposes, just need to get the package name, which can be done the same was as get_config. (I think but actually maybe not, not sure how it works for e.g. astroquery which puts its config file in .astropy/config/... edit: forget this, people would need to specify packageormod in that case)
+ for modname, keys in sec.items():
+ mod = importlib.import_module(f"astropy.{modname}")
actually this doesn't work, sec.items() just returns the caller module (config.configuration) and not the list of modules that would need to be reloaded. And I don't know how to get this list (we would need to reload all conf objects for the package but we don't store that list).
Activity
mhvk commentedon May 13, 2025
A fix is the following, but this is astropy specific, so not quite correct. It may be better to make
valuesome kind of weakref link to the actual configuration. CC @saimn since the caching in #17461 is what is causing the problems.pllim commentedon May 13, 2025
Thanks for investigating, @mhvk !
I think this is a release blocker for astropy v7.1.0. We cannot ship a release with broken public API that affects config for downstream packages. Simplest is to revert #17461 unless someone has a better idea. And definitely need RC2 now after this is patched. What do you think @astropy/astropy-project-release-team ?
Also cc @Cadair since apparently he is very into subclassing config stuff downstream.
saimn commentedon May 13, 2025
Darn! There are too many ways to do stuff with this config API...
We could do what @mhvk proposes, just need to get the package name, which can be done the same was as
get_config. (I think but actually maybe not, not sure how it works for e.g. astroquery which puts its config file in... edit: forget this, people would need to specify.astropy/config/packageormodin that case)saimn commentedon May 14, 2025
actually this doesn't work,
sec.items()just returns the caller module (config.configuration) and not the list of modules that would need to be reloaded. And I don't know how to get this list (we would need to reload all conf objects for the package but we don't store that list).