Skip to content

Foreign Key Validation Does Not Work As Expected #136

@baalmael

Description

@baalmael

ForeignKey.validate(Table table) implements something like a foreign key check for self-referencing FK but it does not work correctly.

Let me explain:
In the tests there is this schema (population_schema_for_fk_check.json):

{
  "fields": [
...
  ],
    "foreignKeys": [
    {
      "fields": ["check_city", "check_year"],
      "reference": {
        "resource": "",
        "fields": ["city", "year"]
      }
    }
  ]
}

When we run the test with the following Data the test show a false negative:

False Negative Data:

city year population check_city check_year
london 2017 8 780 000 paris 2017
paris 2017 2 240 000 paris 2017

Result: io.frictionlessdata.tableschema.exception.ForeignKeyException: Foreign key [check_city-> city] violation : expected: paris found: london

The implementation checks if the value of the foreign key is the same as the reference in the same row which is not how foreign keys work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions