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

[bug] Missing required positional argument in PydanticFieldValidator initialization #550

Closed
thekaranacharya opened this issue Jan 22, 2024 · 2 comments
Assignees
Labels
bug Something isn't working Stale urgent

Comments

@thekaranacharya
Copy link
Contributor

thekaranacharya commented Jan 22, 2024

Describe the bug
In the __init__ method of PydanticFieldValidator, the kwarg field_validator is not passed along in the super call as follows:
super().__init__(on_fail, **kwargs).

Location:

def __init__(
self,
field_validator: Callable,
on_fail: Optional[Callable[..., Any]] = None,
**kwargs,
):
self.field_validator = field_validator
super().__init__(on_fail, **kwargs)

This causes the argument field_validator to not propagate through all the future calls, causing the runtime validator initialization to fail with the following error:

TypeError: init() missing 1 required positional argument: 'field_validator'

To Reproduce
Steps to reproduce the behavior:

  1. Define the prompt
  2. Define the Pydantic class and add the PydanticFieldValidator for a field as follows:
    field_name: int = Field(description="Some description", validators=[PydanticFieldValidator(field_validator=your_validation_function, on_fail="fix")])
  3. Initialise the guard as follows: guard = gd.Guard.from_pydantic(output_class=<PydanticClassName>, prompt=prompt)

Expected behavior
The error should not be raised.

Library version:
v0.3.2 (Latest version as of now)

Probable fix
Like in the __init__ methods for all other validators, we explicitly pass in the required argument in the super call alongwith any other kwargs as follows:

def __init__(
        self,
        arg_1: Any,
        on_fail: Optional[Callable[..., Any]] = None,
        **kwargs,
    ):
        super().__init__(on_fail, arg_1=arg_1, **kwargs)
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Aug 22, 2024
Copy link

github-actions bot commented Sep 5, 2024

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale urgent
Projects
None yet
Development

No branches or pull requests

1 participant