Skip to content

Errors in property input_file_model are not raised #182

@cchall

Description

@cchall

If an error occurs in the cached_property input_file_model of the Code base model the error is not raised and the instantiated model will not have an input_file_model property. Which eventually does raise an error when input_file_model is used.

Attempts to do a very simple reproduction this do not yield the same behavior so far. I'm not sure what the underlying cause for this is.

Example:

from pydantic import BaseModel
from functools import cached_property

class Sim(BaseModel):
    sim_name: str
    @property
    def foo(self):
        print(not_a_variable)
        print(self.sim_name * 5)
        
class Model(BaseModel):
    sim: Sim
    def model_post_init(self, __context) -> None:
        x = self.sim.foo
Model(sim={'sim_name': 'bob'})  

Raises as expected:

NameError: name 'not_a_variable' is not defined

and not (as seen in Configuration right now):

"AttributeError: 'Sim' object has no attribute 'foo'"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions