Skip to content

Commit

Permalink
Ignore mypy errors around models
Browse files Browse the repository at this point in the history
Mypy for some reason isn't correctly picking up on types when dealing
with many-to-many relationships. Ignore for now.
  • Loading branch information
naglepuff committed Aug 29, 2023
1 parent 7b693aa commit 189bbf4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion nmdc_server/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_study_image(db: Session, study_id: str) -> Optional[bytes]:
return None


def get_doi(db: Session, doi_id: str) -> models.DOIInfo:
def get_doi(db: Session, doi_id: str) -> Optional[models.DOIInfo]:
doi = db.query(models.DOIInfo).get(doi_id)
return doi

Expand Down
17 changes: 8 additions & 9 deletions nmdc_server/ingest/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from nmdc_server.crud import create_study, get_doi
from nmdc_server.ingest.common import extract_extras, extract_value
from nmdc_server.ingest.doi import upsert_doi
from nmdc_server.models import DOIInfo, DOIType, PrincipalInvestigator
from nmdc_server.models import DOIType, PrincipalInvestigator
from nmdc_server.schemas import StudyCreate


Expand Down Expand Up @@ -66,22 +66,21 @@ def load(db: Session, cursor: Cursor):
obj["image"] = get_study_image_data(obj.pop("study_image", []))

publication_dois = [transform_doi(d) for d in obj.pop("publications", [])]

award_dois = [transform_doi(doi) for doi in obj.pop("award_dois", [])]
dataset_dois = [transform_doi(doi) for doi in obj.pop("dataset_dois", [])]

for doi in publication_dois:
upsert_doi(db, doi, DOIType.PUBLICATION)

for doi in award_dois:
upsert_doi(db, doi, DOIType.AWARD)

# slot doesn't exist yet
# for doi in dataset_dois:
# upsert_doi(db, doi, DOIType.DATASET)
for doi in dataset_dois:
upsert_doi(db, doi, DOIType.DATASET)

new_study = create_study(db, Study(**obj))

for doi in publication_dois + award_dois:
doi = get_doi(db, doi)
if doi:
new_study.dois.append(doi)
for doi_id in publication_dois + award_dois + dataset_dois:
doi_object = get_doi(db, doi_id)
if doi_object:
new_study.dois.append(doi_object) # type: ignore
9 changes: 5 additions & 4 deletions nmdc_server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class Study(Base, AnnotatedModel):
gold_name = Column(String, nullable=False, default="")
gold_description = Column(String, nullable=False, default="")
scientific_objective = Column(String, nullable=False, default="")
# doi = Column(String, ForeignKey("doi_info.id"), nullable=True)
dois = relationship("DOIInfo", secondary=study_doi_association, back_populates="studies")
multiomics = Column(Integer, nullable=False, default=0)

Expand Down Expand Up @@ -278,15 +277,15 @@ def open_in_gold(self) -> Optional[str]:

@property
def award_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.AWARD]
return [d for d in self.dois if d.doi_type == DOIType.AWARD] # type: ignore

@property
def publication_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.PUBLICATION]
return [d for d in self.dois if d.doi_type == DOIType.PUBLICATION] # type: ignore

@property
def dataset_dois(self) -> list[DOIInfo]:
return [d for d in self.dois if d.doi_type == DOIType.DATASET]
return [d for d in self.dois if d.doi_type == DOIType.DATASET] # type: ignore

@property
def doi_map(self) -> Dict[str, Any]:
Expand All @@ -295,6 +294,8 @@ def doi_map(self) -> Dict[str, Any]:
doi_info[award_doi.id] = award_doi.info
for publication_doi in self.publication_dois:
doi_info[publication_doi.id] = publication_doi.info
for dataset_doi in self.dataset_dois:
doi_info[dataset_doi.id] = dataset_doi.info
return doi_info


Expand Down

0 comments on commit 189bbf4

Please sign in to comment.