pepkit / pepdbagent

Database for storing sample metadata
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

`Connection.upload_project()` with `update=True` doesn't work if the project name is identical. Throws `Attribute Error` #35

Closed nleroy917 closed 2 years ago

nleroy917 commented 2 years ago

When I try to upload a project with the update=True flag, pepdbagent raises an AttributeError. I think I've confirmed that this occurs only if the project already exists.

Steps to reproduce:

  1. Start with fresh database:
    
    DROP TABLE projects;

SET client_encoding = 'LATIN1';

CREATE TABLE projects ( id BIGSERIAL NOT NULL, namespace TEXT NOT NULL, name TEXT NOT NULL, tag TEXT NOT NULL, digest TEXT NOT NULL, -- shoud be changed to CHARACTER project_value jsonb NOT NULL, anno_info jsonb, -- annotation information CONSTRAINT id PRIMARY KEY (namespace, name, tag) );

2. Connect to database:
```python
>>> conn = Connection(
...     host="localhost",
...     user="postgres",
...     password="docker"
... )
  1. Connect to database and verify state:
    >>> conn.get_all_projects()
    []
  2. Upload project:
    >>> conn.upload_project(p, namespace="demo", name="BiocProject")
    [INFO] [13:21:08] Creating digest for: BiocProject
    [INFO] [13:21:08] Uploading BiocProject project...
    [INFO] [13:21:08] Project: 'demo/BiocProject:default' was successfully uploaded.
  3. Change project and update:
    
    >>> p.name = 'biocproject'
    >>> conn.upload_project(p, namespace="demo", name="BiocProject", update=True)
    [INFO] [13:21:33] Creating digest for: biocproject
    [INFO] [13:21:33] Uploading BiocProject project...
    [INFO] [13:21:33] Creating digest for: biocproject
    Traceback (most recent call last):
    File "/Users/nathanleroy/uva/lab/code/pephub/.venv/lib/python3.9/site-packages/pepdbagent/pepdbagent.py", line 132, in upload_project
    cursor.execute(
    psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "id"
    DETAIL:  Key (namespace, name, tag)=(demo, BiocProject, default) already exists.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File ".venv/lib/python3.9/site-packages/pepdbagent/pepdbagent.py", line 153, in upload_project self.update_project( File ".venv/lib/python3.9/site-packages/pepdbagent/pepdbagent.py", line 215, in update_project proj_annot = Annotation().create_new_annotation( File ".venv/lib/python3.9/site-packages/pepdbagent/pepannot.py", line 78, in create_new_annotation for dict_key in anno_dict.keys(): AttributeError: 'str' object has no attribute 'keys'