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

Global configuration item not always being used #736

Open
wlymanambry opened this issue Apr 12, 2024 · 1 comment
Open

Global configuration item not always being used #736

wlymanambry opened this issue Apr 12, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@wlymanambry
Copy link

wlymanambry commented Apr 12, 2024

Describe the bug
I set a global_config setting like:

global_config.normalizer.shuffle_direction = 5

I then call assembly_mapper:

 variant_mapper: assemblymapper.AssemblyMapper = assemblymapper.AssemblyMapper(
        connection,
        assembly_name="GRCh37",
        alt_aln_method="splign",
        normalize=1,
        prevalidation_level="INTRINSIC",
    )

with a print statement, I can see that this config value is set correctly here in assembly mapper:
image

But when the Normalizer class is initialized, it is pulling whatever value is in the _data/defaults.ini file (and I'm not sure why)

A print here shows this is '3' instead of the expected 5 value that was set:
image

To Reproduce
Described above

Expected behavior
For this configuration value to be set globally

@jsstevenson jsstevenson added the bug Something isn't working label Apr 12, 2024
@jsstevenson jsstevenson self-assigned this May 30, 2024
@davmlaw
Copy link
Contributor

davmlaw commented Dec 23, 2024

This is caused because Python evaluates default argument values once when the method is defined, rather than at call time, so these are setting the value when the program started up NOT the value after you change it.

So when you import this code:

class Normalizer:
    """Perform variant normalization"""

    def __init__(
        self,
        hdp,
        cross_boundaries=hgvs.global_config.normalizer.cross_boundaries,
        shuffle_direction=hgvs.global_config.normalizer.shuffle_direction,
        alt_aln_method=hgvs.global_config.mapping.alt_aln_method,
        validate=hgvs.global_config.normalizer.validate,
        variantmapper=None,
    ):

It is being converted to eg:

In [7]: from hgvs.normalizer import Normalizer

In [8]: Normalizer.__init__?
Signature:
Normalizer.__init__(
    self,
    hdp,
    cross_boundaries=False,
    shuffle_direction=3,
    alt_aln_method='splign',
    validate=True,
    variantmapper=None,
)

So there are 2 fixes:

a) Make global_config read only (throwing an exception in setattr) saying that it is designed to run off ini files and is NOT modifiable

b) Go through and replace all default arguments set from global config with None, then in the constructor, check if is not None then set off global config (this will pull in the present value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants