Skip to content

Commit 207e4f4

Browse files
fix: do not detect resource type if type is provided by user (#1690)
- fixes #1688
1 parent fa0d9ed commit 207e4f4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

frictionless/resource/__spec__/test_datatype.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from frictionless import Resource, resources
4+
from frictionless.resources.json import SchemaResource
45

56
# File
67

@@ -162,3 +163,16 @@ def test_resource_from_descriptor_with_class_datatype():
162163
assert resource.type == "table"
163164
assert resource.datatype == "table"
164165
assert isinstance(resource, resources.TableResource)
166+
167+
168+
def test_schema_resource_with_path_property():
169+
# Non regression test for issue #1688
170+
schema_descriptor = {
171+
"name": "schema",
172+
"path": "abc",
173+
"fields": [],
174+
}
175+
resource = Resource(schema_descriptor, datatype="schema")
176+
assert resource.type == "json"
177+
assert resource.datatype == "schema"
178+
assert isinstance(resource, SchemaResource)

frictionless/resource/factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ def __call__(
4545
path = source
4646
if isinstance(source, str):
4747
path = helpers.join_basepath(source, basepath=basepath)
48-
md_type = Detector.detect_metadata_type(path, format=options.get("format"))
48+
49+
md_type = options.get("datatype")
50+
if not md_type:
51+
md_type = Detector.detect_metadata_type(
52+
path, format=options.get("format")
53+
)
54+
4955
if md_type != "resource":
5056
options["path" if isinstance(source, str) else "data"] = source
5157
resource = cls(control=control, basepath=basepath, **options) # type: ignore

0 commit comments

Comments
 (0)