pepkit / pepdbagent

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

`KeyError` when using `get_namespace_information()` function #34

Closed nleroy917 closed 2 years ago

nleroy917 commented 2 years ago

I was uploading PEPs with pepdbagent and I noticed with the lastest version, I get this error after uploading a project and trying to access it:

File "pepdbagent/pepdbagent.py", line 436, in <listcomp>     "description": p[4]["proj_description"], KeyError: 'proj_description'

I'm not sure what I did wrong, but here are the steps to reproduce:

  1. Drop projects table with DROP TABLE projects
  2. Use sql here to create fresh table
  3. Connect to database in python and upload a project:
    >>> from pepdbagent import Connection
    >>> import peppy
    >>> p = peppy.Project("examples/demo/BiocProject/project_config.yaml")
    >>> conn = Connection(
    ...     host="localhost",
    ...     user="postgres",
    ...     password="docker"
    ... )
    >>> conn.upload_project(p, namespace="demo", name="BiocProject")
    >>> conn.get_namespace_info("demo")
  4. Observe error

Interestingly, I can still grab the project:

>>> conn.get_project_by_registry("demo/BiocProject")
Project
_config_file: null
_sample_table_path: null
_subsample_tables_path: null
_samples: 
 - Sample 'laminB1Lads' in Project (None)
nleroy917 commented 2 years ago

Can't reproduce anymore. I might have had an old cached version somewhere I was using. I'll close for now and if it comes back up I'll reopen.

nleroy917 commented 2 years ago

Never mind, I have a reproducible example. It's when you don't specify key-value pairs in the function signature.

>>> from pepdbagent import Connection
>>> import peppy
>>> p = peppy.Project("examples/demo/BiocProject/project_config.yaml")
>>> conn = Connection(
...     host="localhost",
...     user="postgres",
...     password="docker"
... )
>>> conn.upload_project(p, "demo", "BiocProject") # <--- note this line change
>>> conn.get_namespace_info("demo")
"description": p[4]["proj_description"],
KeyError: 'proj_description'

As before, the project got uploaded successfully, since calling conn.get_project_by_registry("demo/BiocProject") returns the full peppy.Project object.

khoroshevskyi commented 2 years ago

I have changed it few days ago, now pepdbagent shoudn't have this problem. I have created new class pepannot, so it will handle this error: check new code here: https://github.com/pepkit/pepdbagent/blob/3478eade8709f2f30bcba5074ff5a2e20d6e972c/pepdbagent/pepdbagent.py#L440-L441

nleroy917 commented 2 years ago

Okay. That's odd it was broken yesterday, but fine now.