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

Static Method Not Reflecting Instance-Specific Argument in Dynamically Created ModelSchema Class #1180

Open
Alex-Sichkar opened this issue May 31, 2024 · 0 comments

Comments

@Alex-Sichkar
Copy link

Description:
I encountered an issue with dynamically creating schema classes where a static method within the class does not reflect an instance-specific argument. Below is the code snippet illustrating the problem:

class get_some_schema(a=False):
    class SomeSchema(ModelSchema):
        class Meta:
            model = SomeModel
            fields = ['some_field']

           @staticmethod
           def resolve_some_field(obj):
               print(f"{a=}")
               return "resolved field"

Steps to Reproduce:

1. Instantiate the schema class with different arguments:

s1 = get_some_schema()
s2 = get_some_schema(True)

2. Call the resolve_some_field method on both instances:

s1.resolve_some_field(None)  # Outputs: a=False
s2.resolve_some_field(None)  # Outputs: a=False (expected: a=True)

Versions (please complete the following information):

  • Python version: 3.12
  • Django version: 4.2.11
  • Django-Ninja version: 1.1.0
  • Pydantic version: 2.7.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant