Config: Fix existing value check

If a sub-field exists in the model provided to the file generator,
use it. Otherwise always fallback to the default factory. This prevents
any subsequent errors from setting None.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2024-09-16 17:51:40 -04:00
parent c715094cdc
commit e60c4ba5bc

View File

@@ -496,8 +496,8 @@ def generate_config_file(
for field, field_data in schema.model_fields.items():
# Fetch from the existing model class if it's passed
# Probably can use this on schema too, but play it safe
if model:
subfield_model = getattr(model, field, None)
if model and hasattr(model, field):
subfield_model = getattr(model, field)
else:
subfield_model = field_data.default_factory()