Source: json-schema-to-pydantic
Version: 0.4.11-1
Severity: serious
Tags: ftbfs

json-schema-to-pydantic's tests fail with pydantic 2.13 in unstable (on 
both Python 3.13 and 3.14).  Let me know if you need help puzzling this 
out.

=================================== FAILURES ===================================
_____________________________ test_one_of_with_ref _____________________________

    def test_one_of_with_ref():
        """Test oneOf handler with a $ref."""
        handler = create_handler()

        root_schema = {
            "$defs": {
                "Cat": {
                    "type": "object",
                    "properties": {
                        "type": {"const": "cat", "description": "Type 
discriminator"},
                        "meow_volume": {"type": "integer"},
                    },
                    "required": ["type", "meow_volume"],
                }
            }
        }
        schema = {
            "oneOf": [
                {
                    "type": "object",
                    "properties": {
                        "type": {"const": "dog"},
                        "bark_pitch": {"type": "string"},
                    },
                    "required": ["type", "bark_pitch"],
                },
                {"$ref": "#/$defs/Cat"},
            ]
        }

        model = handler.handle_one_of(schema["oneOf"], root_schema)
        assert issubclass(model, RootModel)

        # Test dog variant
        dog_instance = model(root={"type": "dog", "bark_pitch": "high"})
        assert dog_instance.root.type == "dog"
        assert dog_instance.root.bark_pitch == "high"

        # Test cat variant (resolved from $ref)
        cat_instance = model(root={"type": "cat", "meow_volume": 10})
        assert cat_instance.root.type == "cat"
        assert cat_instance.root.meow_volume == 10

        # Check field descriptions from referenced schema
        # Access the Union arguments inside Annotated: 
annotation.__args__[0].__args__
>       union_args = model.model_fields["root"].annotation.__args__[0].__args__
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/test_handlers.py:502:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <class 'json_schema_to_pydantic.handlers.Variant_dog'>, item = '__args__'

    def __getattr__(self, item: str) -> Any:
        """This is necessary to keep attribute access working for class 
attribute access."""
        private_attributes = self.__dict__.get('__private_attributes__')
        if private_attributes and item in private_attributes:
            return private_attributes[item]
>       raise AttributeError(item)
E       AttributeError: __args__

/usr/lib/python3/dist-packages/pydantic/_internal/_model_construction.py:290: 
AttributeError
_________________________ test_one_of_populate_by_name _________________________

    def test_one_of_populate_by_name():
        """Test oneOf handler with populate_by_name=True."""
        handler = create_handler()

        schema = {
            "oneOf": [
                {
                    "type": "object",
                    "properties": {
                        "type": {"const": "user"},
                        "username": {"type": "string", "alias": "user_name"},
                    },
                    "required": ["type", "username"],
                },
                {
                    "type": "object",
                    "properties": {
                        "type": {"const": "admin"},
                        "admin_level": {"type": "integer", "alias": 
"adminLevel"},
                    },
                    "required": ["type", "admin_level"],
                },
            ]
        }

        model = handler.handle_one_of(
            schema["oneOf"],
            {},
            populate_by_name=True,
        )

        from typing import get_args

>       types = get_args(model.model_fields["root"].annotation)[0].__args__
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/test_handlers.py:862:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <class 'json_schema_to_pydantic.handlers.Variant_user'>
item = '__args__'

    def __getattr__(self, item: str) -> Any:
        """This is necessary to keep attribute access working for class 
attribute access."""
        private_attributes = self.__dict__.get('__private_attributes__')
        if private_attributes and item in private_attributes:
            return private_attributes[item]
>       raise AttributeError(item)
E       AttributeError: __args__

/usr/lib/python3/dist-packages/pydantic/_internal/_model_construction.py:290: 
AttributeError
=============================== warnings summary ===============================
tests/test_model_builder.py::test_json_schema_extra_with_user_example
  
/build/reproducible-path/json-schema-to-pydantic-0.4.11/.pybuild/cpython3_3.14_json-schema-to-pydantic/build/tests/test_model_builder.py:560:
 PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is 
deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: 
'is_core_field'). Deprecated in Pydantic V2.0 to be removed in V3.0. See 
Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.13/migration/
    v: int = Field(..., description="This is a field", is_core_field=True)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_handlers.py::test_one_of_with_ref - AttributeError: __args__
FAILED tests/test_handlers.py::test_one_of_populate_by_name - AttributeError:...

Thanks,

-- 
Colin Watson (he/him)                              [[email protected]]

Reply via email to