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

Duplicate key error when setting table metadata #3818

Closed
seancolsen opened this issue Sep 10, 2024 · 3 comments
Closed

Duplicate key error when setting table metadata #3818

seancolsen opened this issue Sep 10, 2024 · 3 comments
Assignees
Labels
ready Ready for implementation work: backend Related to Python, Django, and simple SQL

Comments

@seancolsen
Copy link
Contributor

Steps to reproduce

  1. Pick a table and find its oid. In this example we'll use 716798.

  2. Set import_verified to false.

    {
      "jsonrpc": "2.0",
      "method": "tables.metadata.set",
      "id": 0,
      "params": {
        "database_id": 1,
        "table_oid": 716798,
        "metadata": {
          "import_verified": false
        }
      }
    }

    This works.

  3. Set import_verified to true.

    {
      "jsonrpc": "2.0",
      "method": "tables.metadata.set",
      "id": 0,
      "params": {
        "database_id": 1,
        "table_oid": 716798,
        "metadata": {
          "import_verified": true
        }
      }
    }

    This should work.

    But it fails with the following error:

    IntegrityError: duplicate key value violates unique constraint "unique_table_metadata"\nDETAIL: Key (database_id, table_oid)=(1, 716798) already exists.

@seancolsen seancolsen added ready Ready for implementation type: bug work: backend Related to Python, Django, and simple SQL labels Sep 10, 2024
@seancolsen seancolsen added this to the Beta milestone Sep 10, 2024
@Anish9901
Copy link
Member

I am not able to reproduce this @seancolsen, it seems to be working fine for me.

In [38]: a
Out[38]: {'database_id': 1, 'table_oid': 716798, 'metadata': {'import_verified': False}}

In [39]: b
Out[39]: {'database_id': 1, 'table_oid': 716798, 'metadata': {'import_verified': True}}

In [40]: set_table_meta_data(a['table_oid'], a['metadata'], 3)

In [41]: TableMetaData.objects.all()[0].__dict__
Out[41]: 
{'_state': <django.db.models.base.ModelState at 0xffff98f0a4c0>,
 'id': 1,
 'created_at': datetime.datetime(2024, 9, 11, 10, 49, 11, 849546, tzinfo=datetime.timezone.utc),
 'updated_at': datetime.datetime(2024, 9, 11, 10, 55, 47, 170329, tzinfo=datetime.timezone.utc),
 'database_id': 3,
 'table_oid': 716798,
 'data_file_id': None,
 'import_verified': False,
 'column_order': None,
 'record_summary_customized': None,
 'record_summary_template': None}

In [42]: set_table_meta_data(a['table_oid'], b['metadata'], 3)

In [43]: TableMetaData.objects.all()[0].__dict__
Out[43]: 
{'_state': <django.db.models.base.ModelState at 0xffff99886250>,
 'id': 1,
 'created_at': datetime.datetime(2024, 9, 11, 10, 49, 11, 849546, tzinfo=datetime.timezone.utc),
 'updated_at': datetime.datetime(2024, 9, 11, 10, 56, 10, 591215, tzinfo=datetime.timezone.utc),
 'database_id': 3,
 'table_oid': 716798,
 'data_file_id': None,
 'import_verified': True,
 'column_order': None,
 'record_summary_customized': None,
 'record_summary_template': None}

@seancolsen
Copy link
Contributor Author

We chatted about this on a call just now and I was able to get Anish to reproduce this via the UI within my branch for #3819

@seancolsen
Copy link
Contributor Author

This was fixed in a791cb1 in #3819

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Ready for implementation work: backend Related to Python, Django, and simple SQL
Projects
None yet
Development

No branches or pull requests

3 participants