Skip to content

Commit

Permalink
fix: do not detect resource type if type is provided by user (#1690)
Browse files Browse the repository at this point in the history
- fixes #1688
  • Loading branch information
pierrecamilleri authored Sep 24, 2024
1 parent fa0d9ed commit 207e4f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions frictionless/resource/__spec__/test_datatype.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from frictionless import Resource, resources
from frictionless.resources.json import SchemaResource

# File

Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion frictionless/resource/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 207e4f4

Please sign in to comment.