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

Improve error messages for composite keys #1684

Closed
npatki opened this issue Nov 20, 2023 · 0 comments · Fixed by #1705
Closed

Improve error messages for composite keys #1684

npatki opened this issue Nov 20, 2023 · 0 comments · Fixed by #1705
Assignees
Labels
feature request Request for a new feature
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented Nov 20, 2023

Environment Details

  • SDV version: 1.7.0 (latest)

Problem

Currently, composite keys are not supported by any of the synthesizers in the SDV. Yet, some parts of the metadata functionality seem to imply that it is allowed. Until we add support for composite keys (see #613), the metadata should only allow for single-column primary keys.

Example 1: Python Dict

The following metadata has composite keys but it seems to pass the validation check.

from sdv.metadata import MultiTableMetadata

metadata_dict = {
    'tables': {
        'parent': {
            'primary_key': ('id', 'id2'),
            'columns': {
                'id': { 'sdtype': 'id'},
                'id2': { 'sdtype': 'id' },
                'col_A': { 'sdtype': 'numerical' },
            }
            
        },
        'child': {
            'columns': {
                'A_id': { 'sdtype': 'id'},
                'A_id2': { 'sdtype': 'id'},
                'col_C': { 'sdtype': 'numerical'}
            }
            
        }
    },
    'relationships': [{
        'parent_table_name': 'parent',
        'child_table_name': 'child',
        'parent_primary_key': ('id', 'id2'),
        'child_foreign_key': ('A_id', 'A_id2')
    }]
}

metadata = MultiTableMetadata.load_from_dict(metadata_dict)
metadata.validate()

Expectation: I expect that this should not pass validation. It should produce an error:

InvalidMetadataError: The metadata is not valid

Table: parent
'primary_key' must be a string.

Example 2: JSON

In JSON, it is not possible to encode a tuple so many users may try to encode a composite key as a list. This creates a confusing error that seems to imply that using tuples would work.
metadata_example.json

from sdv.metadata import MultiTableMetadata

metadata = MultiTableMetadata.load_from_json(
    filepath='metadata_example.json')

metadata.validate()
InvalidMetadataError: The metadata is not valid

Table: parent
'primary_key' must be a string or tuple of strings.

Expectation: The error message should not imply that a tuple of strings is even a possibility. Because tuples are not allowed in JSON and also we do not support composite keys. The error message should only indicate that it can be a string.

InvalidMetadataError: The metadata is not valid

Table: parent
'primary_key' must be a string.
@npatki npatki added the feature request Request for a new feature label Nov 20, 2023
@amontanez24 amontanez24 added this to the 1.9.0 milestone Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants