Pydantic switchover debugging.
This commit is contained in:
@@ -397,8 +397,8 @@ class BaseClass(Base):
|
||||
"""
|
||||
Custom dunder method to handle potential list relationship issues.
|
||||
"""
|
||||
if key != "_sa_instance_state":
|
||||
logger.debug(f"Attempting to set {key} to {pformat(value)}")
|
||||
# if key != "_sa_instance_state":
|
||||
# logger.debug(f"Attempting to set {key} to {pformat(value)}")
|
||||
try:
|
||||
field_type = getattr(self.__class__, key)
|
||||
except AttributeError:
|
||||
@@ -407,21 +407,25 @@ class BaseClass(Base):
|
||||
logger.debug(f"{key} is an InstrumentedAttribute.")
|
||||
match field_type.property:
|
||||
case ColumnProperty():
|
||||
logger.debug(f"Setting ColumnProperty to {value}")
|
||||
# logger.debug(f"Setting ColumnProperty to {value}")
|
||||
return super().__setattr__(key, value)
|
||||
case _RelationshipDeclared():
|
||||
logger.debug(f"Setting _RelationshipDeclared to {value}")
|
||||
logger.debug(f"{self.__class__.__name__} Setting _RelationshipDeclared for {key} to {value}")
|
||||
if field_type.property.uselist:
|
||||
logger.debug(f"Setting with uselist")
|
||||
existing = self.__getattribute__(key)
|
||||
# NOTE: This is causing problems with removal of items from lists. Have to overhaul it.
|
||||
if existing is not None:
|
||||
logger.debug(f"{key} Existing: {existing}, incoming: {value}")
|
||||
if isinstance(value, list):
|
||||
value = existing + value
|
||||
# value = existing + value
|
||||
value = value
|
||||
else:
|
||||
value = existing + [value]
|
||||
else:
|
||||
value = [value]
|
||||
value = list(set(value))
|
||||
logger.debug(f"Final value for {key}: {value}")
|
||||
return super().__setattr__(key, value)
|
||||
else:
|
||||
if isinstance(value, list):
|
||||
@@ -429,6 +433,7 @@ class BaseClass(Base):
|
||||
value = value[0]
|
||||
else:
|
||||
raise ValueError("Object is too long to parse a single value.")
|
||||
# value = value
|
||||
return super().__setattr__(key, value)
|
||||
case _:
|
||||
return super().__setattr__(key, value)
|
||||
|
||||
@@ -3,6 +3,7 @@ All kit and reagent related models
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import json, zipfile, yaml, logging, re
|
||||
import sys
|
||||
from pprint import pformat
|
||||
from sqlalchemy import Column, String, TIMESTAMP, JSON, INTEGER, ForeignKey, Interval, Table, FLOAT, BLOB
|
||||
from sqlalchemy.orm import relationship, validates, Query
|
||||
@@ -231,6 +232,7 @@ class KitType(BaseClass):
|
||||
@classmethod
|
||||
def query_or_create(cls, **kwargs) -> Tuple[KitType, bool]:
|
||||
from backend.validators.pydant import PydKitType
|
||||
from backend.validators.omni_gui_objects import BaseOmni
|
||||
new = False
|
||||
disallowed = ['expiry']
|
||||
sanitized_kwargs = {k: v for k, v in kwargs.items() if k not in disallowed}
|
||||
@@ -1074,7 +1076,7 @@ class SubmissionType(BaseClass):
|
||||
new = True
|
||||
for k, v in sanitized_kwargs.items():
|
||||
setattr(instance, k, v)
|
||||
logger.info(f"Instance from query or create: {instance}")
|
||||
logger.info(f"Instance from submissiontype query or create: {instance}")
|
||||
return instance, new
|
||||
|
||||
@classmethod
|
||||
@@ -1298,7 +1300,7 @@ class SubmissionTypeKitTypeAssociation(BaseClass):
|
||||
new = True
|
||||
for k, v in sanitized_kwargs.items():
|
||||
setattr(instance, k, v)
|
||||
logger.info(f"Instance from query or create: {instance}")
|
||||
logger.info(f"Instance from SubmissionTypeKitTypeAssociation query or create: {instance}")
|
||||
return instance, new
|
||||
|
||||
@classmethod
|
||||
@@ -1428,6 +1430,22 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
except AttributeError:
|
||||
return "Blank KitTypeReagentRole"
|
||||
|
||||
@hybrid_property
|
||||
def submissiontype(self):
|
||||
return self.submission_type
|
||||
|
||||
@submissiontype.setter
|
||||
def submissiontype(self, value):
|
||||
self.submission_type = value
|
||||
|
||||
@hybrid_property
|
||||
def kittype(self):
|
||||
return self.kit_type
|
||||
|
||||
@kittype.setter
|
||||
def kittype(self, value):
|
||||
self.kit_type = value
|
||||
|
||||
@validates('required')
|
||||
def validate_required(self, key, value):
|
||||
"""
|
||||
@@ -1478,8 +1496,31 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
instance = cls()
|
||||
new = True
|
||||
for k, v in sanitized_kwargs.items():
|
||||
logger.debug(f"Key: {k} has value: {v}")
|
||||
match k:
|
||||
case "kittype" | "kit_type":
|
||||
k = "kit_type"
|
||||
if isinstance(v, str):
|
||||
v = KitType.query(name=v)
|
||||
else:
|
||||
v = v.instance_object
|
||||
case "submissiontype" | "submission_type":
|
||||
k = "submission_type"
|
||||
if isinstance(v, str):
|
||||
v = SubmissionType.query(name=v)
|
||||
else:
|
||||
v = v.instance_object
|
||||
case "reagentrole" | "reagent_role":
|
||||
k = "reagent_role"
|
||||
if isinstance(v, str):
|
||||
v = ReagentRole.query(name=v)
|
||||
else:
|
||||
v = v.instance_object
|
||||
case _:
|
||||
pass
|
||||
setattr(instance, k, v)
|
||||
logger.info(f"Instance from query or create: {instance}")
|
||||
logger.info(f"Instance from query or create: {instance.__dict__}")
|
||||
# sys.exit()
|
||||
return instance, new
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -460,6 +460,7 @@ class BasicSubmission(BaseClass, LogMixin):
|
||||
"""
|
||||
rows = range(1, plate_rows + 1)
|
||||
columns = range(1, plate_columns + 1)
|
||||
logger.debug(f"sample list for plate map: {pformat(sample_list)}")
|
||||
# NOTE: An overly complicated list comprehension create a list of sample locations
|
||||
# NOTE: next will return a blank cell if no value found for row/column
|
||||
output_samples = [next((item for item in sample_list if item['row'] == row and item['column'] == column),
|
||||
@@ -1536,6 +1537,7 @@ class Wastewater(BasicSubmission):
|
||||
continue
|
||||
thing['tooltip'] = f"Sample Name: {thing['name']}\nWell: {thing['sample_location']}"
|
||||
dummy_samples.append(thing)
|
||||
logger.debug(f"Dummy samples for 24 well: {pformat(dummy_samples)}")
|
||||
output['origin_plate'] = self.__class__.make_plate_map(sample_list=dummy_samples, plate_rows=4,
|
||||
plate_columns=6)
|
||||
# logger.debug(f"PCR info: {output['pcr_info']}")
|
||||
|
||||
Reference in New Issue
Block a user