diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index 4e1d1546b9..f61e8101fa 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -1,6 +1,7 @@ import pytest from frictionless import Resource, resources +from frictionless.resources.json import SchemaResource # File @@ -162,3 +163,16 @@ def test_resource_from_descriptor_with_class_datatype(): assert resource.type == "table" assert resource.datatype == "table" assert isinstance(resource, resources.TableResource) + + +def test_schema_resource_with_path_property(): + # Non regression test for issue #1688 + schema_descriptor = { + "name": "schema", + "path": "abc", + "fields": [], + } + resource = Resource(schema_descriptor, datatype="schema") + assert resource.type == "json" + assert resource.datatype == "schema" + assert isinstance(resource, SchemaResource) diff --git a/frictionless/resource/factory.py b/frictionless/resource/factory.py index dd6867ce10..a2dcc798e8 100644 --- a/frictionless/resource/factory.py +++ b/frictionless/resource/factory.py @@ -45,7 +45,13 @@ def __call__( path = source if isinstance(source, str): path = helpers.join_basepath(source, basepath=basepath) - md_type = Detector.detect_metadata_type(path, format=options.get("format")) + + md_type = options.get("datatype") + if not md_type: + md_type = Detector.detect_metadata_type( + path, format=options.get("format") + ) + if md_type != "resource": options["path" if isinstance(source, str) else "data"] = source resource = cls(control=control, basepath=basepath, **options) # type: ignore