-
Notifications
You must be signed in to change notification settings - Fork 992
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
Do not overwrite existing attributes #8728
Conversation
This is a safeguard against introducing a bug. This edit prevents the config loading code from overwriting the value of an existing attribute. The config loading procedure automatically creates attributes of the GalaxyAppConfiguration object for each property in the schema. If the schema contains a property with the same name as an existing attribute (e.g., `reloadable_options`, `schema`, etc.), that attribute will be overwritten. Worse, if the call to `_set_config_base()` is moved before the call to `_create_attributes_from_raw_config()`, the values of `config_dir` and `data_dir` will be set to `None`, because those are present in the schema. This fix prevents this from happening.
lib/galaxy/config/__init__.py
Outdated
if not hasattr(self, key): | ||
setattr(self, key, value) | ||
else: | ||
log.debug("Can't override existing attribute %s ", key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.debug("Can't override existing attribute %s ", key) | |
log.debug("Can't override existing attribute '%s'", key) |
or should that be a full-blown exception instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, probably. I want to think a bit and see if I can come up with a use case for when we want just a warning.. If I can't think of one, I'll change this shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be safer to raise an Exception now and change the code if/when an use case emerges.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look right?
raise ConfigurationError("Attempting to override existing attribute %s ", key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write it as:
if hasattr(self, key):
raise ConfigurationError("Attempting to override existing attribute '%s'" % key)
setattr(self, key, value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course.
Error in circleci is unrelated (nondeterministic test) |
This commit drops the exception that guarded against accidental overwriting of existing attributes, and instead ignores the setattr call, logging a debug message (which was initialy proposed in galaxyproject#8728). Rationale: with the previous version, base configuration properties (config_dir, data_dir, etc.) had to be set *after* this method was called (otherwise an exeption was raised), but *before* any path resolving code (because these properties are used for path resolution). As a result, config loading required a rigid sequence of steps: 1: load defaults and kwargs, create all config attributes. 2: set base configuration properties [CANNOT MOVE THIS] 3: resolve paths, do the rest: load individual properties, etc. However, setting base configuration properties is a special case that is *independent of schema loading*, is handled separately (in set_config_base), and takes presendence over schema loading procedures. This modification makes config loading more flexible, and logical: 1. set base configuration properties 2. do the rest (now any refactoring can go here)
This commit drops the exception that guarded against accidental overwriting of existing attributes, and instead ignores the setattr call, logging a debug message (which was initialy proposed in galaxyproject#8728). Rationale: with the previous version, base configuration properties (config_dir, data_dir, etc.) had to be set *after* this method was called (otherwise an exeption was raised), but *before* any path resolving code (because these properties are used for path resolution). As a result, config loading required a rigid sequence of steps: 1: load defaults and kwargs, create all config attributes. 2: set base configuration properties [CANNOT MOVE THIS] 3: resolve paths, do the rest: load individual properties, etc. However, setting base configuration properties is a special case that is *independent of schema loading*, is handled separately (in set_config_base), and takes presendence over schema loading procedures. This modification makes config loading more flexible, and logical: 1. set base configuration properties 2. do the rest (now any refactoring can go here)
This commit drops the exception that guarded against accidental overwriting of existing attributes, and instead ignores the setattr call, logging a debug message (which was initialy proposed in galaxyproject#8728). Rationale: with the previous version, base configuration properties (config_dir, data_dir, etc.) had to be set *after* this method was called (otherwise an exeption was raised), but *before* any path resolving code (because these properties are used for path resolution). As a result, config loading required a rigid sequence of steps: 1: load defaults and kwargs, create all config attributes. 2: set base configuration properties [CANNOT MOVE THIS] 3: resolve paths, do the rest: load individual properties, etc. However, setting base configuration properties is a special case that is *independent of schema loading*, is handled separately (in set_config_base), and takes precendence over schema loading procedures. This modification makes config loading more flexible, and logical: 1. set base configuration properties 2. do the rest (now any refactoring can go here) (cherry-picked from closed galaxyproject#9307)
This commit drops the exception that guarded against accidental overwriting of existing attributes, and instead ignores the setattr call, logging a debug message (which was initialy proposed in galaxyproject#8728). Rationale: with the previous version, base configuration properties (config_dir, data_dir, etc.) had to be set *after* this method was called (otherwise an exeption was raised), but *before* any path resolving code (because these properties are used for path resolution). As a result, config loading required a rigid sequence of steps: 1: load defaults and kwargs, create all config attributes. 2: set base configuration properties [CANNOT MOVE THIS] 3: resolve paths, do the rest: load individual properties, etc. However, setting base configuration properties is a special case that is *independent of schema loading*, is handled separately (in set_config_base), and takes precendence over schema loading procedures. This modification makes config loading more flexible, and logical: 1. set base configuration properties 2. do the rest (now any refactoring can go here) (cherry-picked from closed galaxyproject#9307)
This commit drops the exception that guarded against accidental overwriting of existing attributes, and instead ignores the setattr call, logging a debug message (which was initialy proposed in galaxyproject#8728). Rationale: with the previous version, base configuration properties (config_dir, data_dir, etc.) had to be set *after* this method was called (otherwise an exeption was raised), but *before* any path resolving code (because these properties are used for path resolution). As a result, config loading required a rigid sequence of steps: 1: load defaults and kwargs, create all config attributes. 2: set base configuration properties [CANNOT MOVE THIS] 3: resolve paths, do the rest: load individual properties, etc. However, setting base configuration properties is a special case that is *independent of schema loading*, is handled separately (in set_config_base), and takes precendence over schema loading procedures. This modification makes config loading more flexible, and logical: 1. set base configuration properties 2. do the rest (now any refactoring can go here) (cherry-picked from closed galaxyproject#9307)
This is a safeguard against introducing a bug. This edit prevents the
config loading code from overwriting the value of an existing attribute.
The config loading procedure automatically creates attributes of the
GalaxyAppConfiguration object for each property in the schema. If the
schema contains a property with the same name as an existing attribute
(e.g.,
reloadable_options
,schema
, etc.), that attribute will beoverwritten. Worse, if the call to
_set_config_base()
is moved beforethe call to
_create_attributes_from_raw_config()
, the values ofconfig_dir
anddata_dir
will be set toNone
, because those arepresent in the schema. This fix prevents this from happening.