-
-
Notifications
You must be signed in to change notification settings - Fork 386
Creating a Subclassed instance now errors with got an unexpected keyword argument
#1416
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
Comments
#1401 might have caused it |
Might do, yes, but the minimal example is not failing, so it's some quirk of what we are doing in Airflow |
pls provide a repro and I'll see if I can do anything before leaving for my vacation tomorrow afternoon |
I updated the example to include On 25.1.0 we see this:
On 25.2.0 we see this:
|
@hynek No rush at all!, we are happy to pin to !latest for now |
I have got a simple reproducer. Let me try that. |
cc @sscherfke for good measure |
@tirkarthi I've got a reproducer now. Top post has been updated. |
@ashb Thanks, I got the same one but didn't to subclass. import attrs
def _all_after_dag_id_to_kw_only(cls, fields: list[attrs.Attribute]):
i = iter(fields)
f = next(i)
if f.name != "dag_id":
raise RuntimeError("dag_id was not the first field")
yield f
for f in i:
yield f.evolve(kw_only=True)
@attrs.define(repr=False, field_transformer=_all_after_dag_id_to_kw_only, slots=False)
class DAG:
dag_id: str = attrs.field(kw_only=False, validator=attrs.validators.instance_of(str))
dag = DAG(dag_id="test")
print(dag)
|
Walking up the stack to where the field transformer is called, I notice that base_attrs is an empty list, even though collect_mro is true. |
On 24.2.0 : |
Oh, this might be part of the problem, Base.attrs_attrs is empty when a field transformer is used: import attrs
print(f"{attrs.__version__=}")
def _all_after_dag_id_to_kw_only(cls, fields: list[attrs.Attribute]):
i = iter(fields)
f = next(i)
if f.name != "dag_id":
raise RuntimeError("dag_id was not the first field")
yield f
for f in i:
yield f.evolve(kw_only=True)
@attrs.define(field_transformer=_all_after_dag_id_to_kw_only)
class Base:
dag_id: str
has_default: str = "default"
print(attrs.fields(Base)) Prints:
|
Ahhh, got it. The issue is that the field transformer is defined as a generator, so it's exhausted once looking for the |
🎉
Without being able to look at the code: sounds like we should be able to convert it to a tuple on first use? Quick PRs with tests welcome. ;) |
Yup, that was exactly my plan, |
25.3.0 is live and I am gone |
We just noticed this in Airflow CI on upgrading to 25.2.0.
The error is
(Yes, I know your view on subclassing. I don't disagree either)
Minimal repro case:
The text was updated successfully, but these errors were encountered: