Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not detect resource type if type is provided by user #1690

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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