This pull request pinpoints a bug by introducing a new test and a fix for this bug.
The test shows that checking relations of one schema which has two foreign keys targeting the same field raises a "Dict is not iterable" exception.
This is due to the fact that checking relations into the table.iter method does mutate the row values at each foreign key. So the first foreign key test mutate the row value for a field whose original value is needed for the next foreign key to be tested (I also added a test for invalid relation in that case).
The second commit proposes a fix for this case which change the behaviour of the check relations mechanism. The internal _resolve_relations method now returns only the reference value (and not the complete row mutated. the row mutation is done only after all the foreign keys has been tested.
If there are multiple foreign keys on the same field, checking relations replaces this field by the combination of the reference values merging the key/value pairs.
I tried to stick as much as I could to the original code style.
This pull request pinpoints a bug by introducing a new test and a fix for this bug.
The test shows that checking relations of one schema which has two foreign keys targeting the same field raises a "Dict is not iterable" exception. This is due to the fact that checking relations into the table.iter method does mutate the row values at each foreign key. So the first foreign key test mutate the row value for a field whose original value is needed for the next foreign key to be tested (I also added a test for invalid relation in that case).
The second commit proposes a fix for this case which change the behaviour of the check relations mechanism. The internal _resolve_relations method now returns only the reference value (and not the complete row mutated. the row mutation is done only after all the foreign keys has been tested. If there are multiple foreign keys on the same field, checking relations replaces this field by the combination of the reference values merging the key/value pairs.
I tried to stick as much as I could to the original code style.
FYI, I need this fix for this datapackage: https://github.com/medialab/ricardo_data
Thank you for your work.