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

Do not overwrite existing attributes #8728

Merged
merged 3 commits into from
Oct 1, 2019

Conversation

jdavcs
Copy link
Member

@jdavcs jdavcs commented Sep 30, 2019

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.

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.
@jdavcs jdavcs added area/configuration Galaxy's configuration system kind/bug labels Sep 30, 2019
@galaxybot galaxybot added this to the 20.01 milestone Sep 30, 2019
if not hasattr(self, key):
setattr(self, key, value)
else:
log.debug("Can't override existing attribute %s ", key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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)

Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course.

@jdavcs
Copy link
Member Author

jdavcs commented Oct 1, 2019

Error in circleci is unrelated (nondeterministic test)

@nsoranzo nsoranzo merged commit d2cf89f into galaxyproject:dev Oct 1, 2019
jdavcs added a commit to jdavcs/galaxy that referenced this pull request Feb 4, 2020
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)
jdavcs added a commit to jdavcs/galaxy that referenced this pull request Feb 5, 2020
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)
jdavcs added a commit to jdavcs/galaxy that referenced this pull request Feb 15, 2020
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)
jdavcs added a commit to jdavcs/galaxy that referenced this pull request Mar 2, 2020
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)
jdavcs added a commit to jdavcs/galaxy that referenced this pull request Mar 9, 2020
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration Galaxy's configuration system kind/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants