diff --git a/apis_core/utils/helpers.py b/apis_core/utils/helpers.py index a65f83e48..ef67cca5c 100644 --- a/apis_core/utils/helpers.py +++ b/apis_core/utils/helpers.py @@ -75,12 +75,18 @@ def create_object_from_uri(uri: str, model: object, raise_on_fail=False) -> obje if uri.startswith("http"): try: uri = Uri.objects.get(uri=uri) - return uri.root_object + return uri.content_object or uri.root_object except Uri.DoesNotExist: Importer = get_importer_for_model(model) importer = Importer(uri, model) instance = importer.create_instance() - uri = Uri.objects.create(uri=importer.get_uri, root_object=instance) + content_type = ContentType.objects.get_for_model(instance) + uri = Uri.objects.create( + uri=importer.get_uri, + root_object=instance, + content_type=content_type, + object_id=instance.id, + ) return instance if raise_on_fail: content_type = ContentType.objects.get_for_model(model)