Skip to content

Update of primaryKey and foreignKeys when field is renamed #1560

@fjuniorr

Description

@fjuniorr

Currently, when a field is renamed with steps.field_update shouldn't other properties that rely on field.name be updated as well? The examples that came to mind are primaryKey and foreignKeys (if inside a package).

Otherwise frictionless transform could take a valid resource and generate an invalid resource as output. Here's one example:

from frictionless import Resource, Pipeline, steps, Schema

source = Resource("https://raw.githubusercontent.com/frictionlessdata/framework/main/data/transform.csv")
source.schema = Schema.from_descriptor({
    "fields": [
        {"name": "id", "type": "integer"},
        {"name": "name", "type": "string"},
        {"name": "population", "type": "integer"},
    ],
    "primaryKey": ["id"]
})

source.validate()

pipeline = Pipeline(
    steps=[
        steps.field_update(name="id", descriptor={"name": "pkey"}),
    ],
)
target = source.transform(pipeline)
target.validate()
{'valid': False,
 'stats': {'tasks': 1, 'errors': 1, 'warnings': 0, 'seconds': 0.001},
 'warnings': [],
 'errors': [],
 'tasks': [{'name': 'transform',
            'type': 'table',
            'valid': False,
            'place': '<memory>',
            'labels': [],
            'stats': {'errors': 1, 'warnings': 0, 'seconds': 0.001},
            'warnings': [],
            'errors': [{'type': 'schema-error',
                        'title': 'Schema Error',
                        'description': 'Provided schema is not valid.',
                        'message': 'Schema is not valid: primary key '
                                   '"[\'id\']" does not match the fields '
                                   '"[\'pkey\', \'name\', \'population\']"',
                        'tags': [],
                        'note': 'primary key "[\'id\']" does not match the '
                                'fields "[\'pkey\', \'name\', '
                                '\'population\']"'}]}]}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions