Repository: frictionlessdata/frictionless-py

Issue:
Resources with duplicate property "name" in datapackage.json files
# Overview

The `frictionless validate` option doesn't return any error if a datapackage.json contains two resources with the same "name" property.

I believe that it could be validated for two reasons:

Frist: Because as pointed in frictionless [specs](https://specs.frictionlessdata.io/data-resource/#metadata-properties) "if present, the name MUST be unique amongst all resources in this data package".

Second: As I tested, if [package.get_resource function](https://framework.frictionlessdata.io/docs/references/api-reference/#packageget_resource) is needed to extract the resource information, only the first resource listed in my datapackage.json will the returned.

What makes more sense: an error during `frictionless validate` call or return all resources with the same name in package.get_resource function?

---

Please preserve this line to notify @roll (lead of this repository)


Discussion:

Patch:
diff --git a/frictionless/package.py b/frictionless/package.py
index f3cdc7f9..2ce2eb13 100644
--- a/frictionless/package.py
+++ b/frictionless/package.py
@@ -712,6 +712,9 @@ class Package(Metadata):
         # Resources
         for resource in self.resources:
             yield from resource.metadata_errors
+        if len(self.resource_names) != len(set(self.resource_names)):
+            note = "names of the resources are not unique"
+            yield errors.PackageError(note=note)
 
         # Created
         if self.get("created"):


Test patch:
diff --git a/tests/test_package.py b/tests/test_package.py
index c3537d34..0a61a4bf 100644
--- a/tests/test_package.py
+++ b/tests/test_package.py
@@ -1030,3 +1030,15 @@ def test_package_validation_is_not_strict_enough_issue_869():
     assert len(errors) == 2
     assert errors[0].note == 'property "created" is not valid "datetime"'
     assert errors[1].note == 'property "contributors[].email" is not valid "email"'
+
+
+def test_package_validation_duplicate_resource_names_issue_942():
+    package = Package(
+        resources=[
+            Resource(name="name", path="data/table.csv"),
+            Resource(name="name", path="data/table.csv"),
+        ]
+    )
+    errors = package.metadata_errors
+    assert len(errors) == 1
+    assert errors[0].note == "names of the resources are not unique"