Skip to content

Commit

Permalink
fix model_generic python templates to have valid imports for polymorp…
Browse files Browse the repository at this point in the history
…hism
  • Loading branch information
Yousef Haggy committed Dec 8, 2024
1 parent dc175c5 commit 851910d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from typing import TYPE_CHECKING
from importlib import import_module
if TYPE_CHECKING:
{{#mappedModels}}
from {{packageName}}.models.{{model.classVarName}} import {{modelName}}
from {{packageName}}.models.{{model.classFilename}} import {{modelName}}
{{/mappedModels}}

{{/discriminator}}
Expand Down Expand Up @@ -238,7 +238,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
object_type = cls.get_discriminator_value(obj)
{{#mappedModels}}
if object_type == '{{{modelName}}}':
return import_module("{{packageName}}.models.{{model.classVarName}}").{{modelName}}.from_dict(obj)
return import_module("{{packageName}}.models.{{model.classFilename}}").{{modelName}}.from_dict(obj)
{{/mappedModels}}
raise ValueError("{{{classname}}} failed to lookup discriminator value from " +
json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ from typing_extensions import Self
from typing import TYPE_CHECKING
if TYPE_CHECKING:
{{#mappedModels}}
from {{packageName}}.models.{{model.classVarName}} import {{modelName}}
from {{packageName}}.models.{{model.classFilename}} import {{modelName}}
{{/mappedModels}}

{{/discriminator}}
Expand Down Expand Up @@ -261,7 +261,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
object_type = cls.get_discriminator_value(obj)
{{#mappedModels}}
if object_type == '{{{modelName}}}':
return import_module("{{packageName}}.models.{{model.classVarName}}").{{modelName}}.from_dict(obj)
return import_module("{{packageName}}.models.{{model.classFilename}}").{{modelName}}.from_dict(obj)
{{/mappedModels}}

raise ValueError("{{{classname}}} failed to lookup discriminator value from " +
Expand Down

0 comments on commit 851910d

Please sign in to comment.