Doesn't allow duplicate model names
Closed this issue · 2 comments
Even though Django allows for duplicate model names in different apps, Baker throws a AmbiguousModelName
exception if duplicate model names are provided.
In Django this would be solved by using the import as
method --
from app_1 import duplicate_model_name as new_name
from app_2 import duplicate_model_name as new_name_2
Expected behavior
To use declared name of a model to create the model.
Actual behavior
model_bakery.exceptions.AmbiguousModelName: ModelName is a model in more than one app. Use the form "app.model".
Reproduction Steps
Have multiple models in different apps with the same name, and try to create a new instance with model bakery
baker.make("duplicate_model_name")
Versions
Python: 3.9.5
Django: 2.2.20
Model Bakery:1.3.1
The exception message says it all:
Use the form "app.model".
...which in your example would be:
baker.make("app_1.duplicate_model_name")
# or
baker.make("app_2.duplicate_model_name")
Since there is no way for bakery to determine which model you meant, then prefixing the app name is required.
@jjoocceeee I am closing this issue, as there is already a workable method of resolving ambiguous model names (providing the "dotted path" which includes the app name).
Feel free to open up any other issues you have in the future.