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

Fixed issue where config with * could not be filled #53

Merged
merged 6 commits into from
Dec 31, 2023

Conversation

KennethEnevoldsen
Copy link
Contributor

@KennethEnevoldsen KennethEnevoldsen commented Dec 5, 2023

  • fix field exclusion logic (only relevant when validate=False)
  • Added missing alias when creating copy of field
  • copy field (in case validate = True) when using a promise within a positional argument
  • Added test

fixes #47

Comment on lines +922 to +925
field = schema.__fields__[ARGS_FIELD_ALIAS]
schema.__fields__[ARGS_FIELD_ALIAS] = copy_model_field(
field, Any
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a copy of a logic appearing earlier (if it is a promise). It seems like it might be possible to move it outside the 'if promise'-scope.

Comment on lines 951 to 953
field_set = [
k if k != ARGS_FIELD else ARGS_FIELD_ALIAS for k in result.__fields_set__
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If validate=False this avoid removing the "*" key.

@@ -704,6 +705,7 @@ def copy_model_field(field: ModelField, type_: Any) -> ModelField:
default=field.default,
default_factory=field.default_factory,
required=field.required,
alias=field.alias,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This avoids dropping the previous alias for *

@MartinBernstorff
Copy link

MartinBernstorff commented Dec 19, 2023

Hi @svlandeg! We have some functionality dependent on this, any hints as to when this can get reviewed? :-)

Loving the package and super grateful for it, so no pressure, just curious.

@svlandeg
Copy link
Member

svlandeg commented Dec 19, 2023

Hi @svlandeg! We have some functionality dependent on this, any hints as to when this can get reviewed? :-)

Loving the package and super grateful for it, so no pressure, just curious.

I've been meaning to get to this - I saw the downstream blocked issue. Sorry that we haven't gotten to it yet! We have a few end-of-year deadlines that we need to prioritize, but I should be able to review this one on Thursday. Promise!

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

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

@KennethEnevoldsen & @MartinBernstorff: thanks so much for the detailed write-ups, PR and test cases! Super appreciated, especially the cat-themed test ;-)

When I use your minimal example from #47 and follow the Registry.resolve(cfg) route, it still doesn't work - not with cfg or cfg_filled and not on main or with this PR. Is that expected? I'm confused because you noted that the simple Registry.resolve(cfg) should work (even before this PR) but it doesn't on my end.

Maybe all of that is a red herring though. This PR certainly seems to fix the issue with removing the * argument from the filled config. And it allows the Registry.fill(cfg, validate=True) statements to pass, so that all looks good. The logic you implemented with the special handling of ARGS_FIELD_ALIAS looks correct to me as well.

I'll quickly double check with Ines as well, who wrote this code originally IIRC.

@KennethEnevoldsen
Copy link
Contributor Author

especially the cat-themed test ;-)

Seemed like it was an ongoing theme, wanted to match the style ;)

When I use your minimal example from #47 and follow the Registry.resolve(cfg) route, it still doesn't work - not with cfg or cfg_filled and not on main or with this PR. Is that expected? I'm confused because you noted that the simple Registry.resolve(cfg) should work (even before this PR) but it doesn't on my end.

Just double checked that and it actually seems like there is an error in the example. This one works:

import catalogue

from confection import Config, registry


class Registry(registry):
    registry = catalogue.create("psycop", "test_reg")


@Registry.registry.register("test_fn")
def test_fn(*args: int):
    return 2

config_str = """
[test_fn]
@registry = "test_fn"
* = [1, 2]
"""

if __name__ == "__main__":
    cfg = Config().from_str(text=config_str)
    Registry.resolve(cfg)

@ines
Copy link
Member

ines commented Dec 31, 2023

@KennethEnevoldsen Merging this and will release it as v0.1.5a0 for now so you can keep working and we can test it! 👍

@ines ines merged commit 274c40a into explosion:main Dec 31, 2023
21 checks passed
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

Successfully merging this pull request may close these issues.

Unable to fill config if using *args
5 participants