Bug fix in order cart line model. Need to create another _Base for order_line and order_cart_line

This commit is contained in:
Scott Idem
2021-08-07 20:27:45 -04:00
parent 5e02b424a8
commit 65b5e6ade6
7 changed files with 53 additions and 18 deletions

View File

@@ -762,7 +762,7 @@ def redis_lookup_id_random(record_id_random:int|str, table_name:str):
# ### BEGIN ### API Lib General ### lookup_id_random() ### # ### BEGIN ### API Lib General ### lookup_id_random() ###
def lookup_id_random(record_id:int, table_name:str): def lookup_id_random(record_id:int, table_name:str):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
data = { 'id': record_id } data = { 'id': record_id }
@@ -777,7 +777,7 @@ def lookup_id_random(record_id:int, table_name:str):
log.debug(select_results) log.debug(select_results)
log.debug(type(select_results)) log.debug(type(select_results))
if isinstance(select_results, dict): if isinstance(select_results, dict):
log.info(f"""Record ID found: {str(select_results['id_random'])}""") # log.info(f"""Record ID found: {select_results['id_random']}""") # DOES UNCOMMENTING THIS BREAK STUFF???
if record_id_random := select_results.get('id_random'): if record_id_random := select_results.get('id_random'):
return str(record_id_random) return str(record_id_random)
else: else:

View File

@@ -40,9 +40,7 @@ def load_order_cfg_obj(
log.error(e.json()) log.error(e.json())
if model_as_dict: if model_as_dict:
log.debug('**** HERE dict ****')
return order_cfg_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member return order_cfg_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
else: else:
log.debug('**** HERE obj ****')
return order_cfg_obj return order_cfg_obj
# ### END ### API Order Cfg Methods ### load_order_cfg_obj() ### # ### END ### API Order Cfg Methods ### load_order_cfg_obj() ###

View File

@@ -39,8 +39,8 @@ def load_order_line_obj(
order_line_id: int|str, order_line_id: int|str,
limit: int = 1000, limit: int = 1000,
by_alias: bool = True, by_alias: bool = True,
exclude_unset: bool = True, exclude_unset: bool = True, # NOTE: Normally this is True
model_as_dict: bool = False, model_as_dict: bool = False, # NOTE: Normally this is False
) -> Order_Line_Base|dict|bool: ) -> Order_Line_Base|dict|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -51,7 +51,7 @@ def load_order_line_obj(
if order_line_rec := sql_select(table_name='v_order_line', record_id=order_line_id): pass if order_line_rec := sql_select(table_name='v_order_line', record_id=order_line_id): pass
else: return False else: return False
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(order_line_rec) log.debug(order_line_rec)
try: try:

View File

@@ -121,6 +121,15 @@ class Order_Cart_Line_Base(BaseModel):
return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type']) return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type'])
return None return None
@validator('curr_product_id', always=True)
def curr_product_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values.get('curr_product_id_random', None):
return redis_lookup_id_random(record_id_random=values['curr_product_id_random'], table_name='product')
return None
@validator('curr_product_for_id', always=True) @validator('curr_product_for_id', always=True)
def curr_product_for_id_lookup(cls, v, values, **kwargs): def curr_product_for_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING) log.setLevel(logging.WARNING)

View File

@@ -4,14 +4,14 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
from app.db_sql import redis_lookup_id_random from app.db_sql import redis_lookup_id_random, lookup_id_random
from app.lib_general import * from app.lib_general import log, logging
from .common_field_schema import base_fields, default_num_bytes from .common_field_schema import base_fields, default_num_bytes
class Order_Line_Base(BaseModel): class Order_Line_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
id_random: Optional[str] = Field( id_random: Optional[str] = Field(
@@ -28,12 +28,15 @@ class Order_Line_Base(BaseModel):
product_id_random: str product_id_random: str
product_id: Optional[int] product_id: Optional[int]
product_for_type: Optional[str] # Copied from product record product_for_type: Optional[str] # Copied from product record
product_for_id_random: Optional[str] # Copied from product record product_for_id_random: Optional[str] # Copied from product record NOPE
product_for_id: Optional[int] # Copied from product record product_for_id: Optional[int] # Copied from product record
product_type_id: Optional[int] # Copied from product record product_type_id: Optional[int] # Copied from product record
product_type: Optional[str] # WARNING: Copied from product record; dup from look up? probably not use? product_type: Optional[str] # WARNING: Copied from product record; dup from look up? probably not use?
product_type_name: Optional[str] # Copied from product record; from look up product_type_name: Optional[str] # Copied from product record; from look up
product_name: Optional[str] # Copied from product record product_name: Optional[str] # Copied from product record
product_description: Optional[str] # Copied from product record product_description: Optional[str] # Copied from product record
product_unit_price: Optional[int] # Copied from product record product_unit_price: Optional[int] # Copied from product record
@@ -41,12 +44,16 @@ class Order_Line_Base(BaseModel):
curr_product_id_random: str # Should be the same as product_id_random above curr_product_id_random: str # Should be the same as product_id_random above
curr_product_id: Optional[int] # Should be the same as product_id above curr_product_id: Optional[int] # Should be the same as product_id above
# NOTE: This is reversed with for_id_random
curr_product_for_type: Optional[str] # Dynamic from v_order_line curr_product_for_type: Optional[str] # Dynamic from v_order_line
curr_product_for_id_random: Optional[str] # Dynamic from v_order_line
curr_product_for_id: Optional[int] # Dynamic from v_order_line curr_product_for_id: Optional[int] # Dynamic from v_order_line
curr_product_for_id_random: Optional[str] # Dynamic from v_order_line NOPE
curr_product_type_id: Optional[int] # Dynamic from v_order_line curr_product_type_id: Optional[int] # Dynamic from v_order_line
curr_product_type: Optional[str] # Dynamic from v_order_line curr_product_type: Optional[str] # Dynamic from v_order_line
curr_product_type_name: Optional[str] # Dynamic from v_order_line curr_product_type_name: Optional[str] # Dynamic from v_order_line
curr_product_name: Optional[str] # Dynamic from v_order_line curr_product_name: Optional[str] # Dynamic from v_order_line
curr_product_description: Optional[str] # Dynamic from v_order_line curr_product_description: Optional[str] # Dynamic from v_order_line
curr_product_unit_price: Optional[int] # Dynamic from v_order_line curr_product_unit_price: Optional[int] # Dynamic from v_order_line
@@ -121,16 +128,36 @@ class Order_Line_Base(BaseModel):
return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type']) return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type'])
return None return None
@validator('curr_product_for_id', always=True) # @validator('curr_product_for_id_random', always=True)
def curr_product_for_id_lookup(cls, v, values, **kwargs): # def curr_product_for_id_random_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING) # log.setLevel(logging.DEBUG)
# log.debug(locals())
# if values['curr_product_for_id'] and values['curr_product_for_type']:
# return redis_lookup_id(record_id=values['curr_product_for_id'], table_name=values['curr_product_for_type'])
# return None
@validator('curr_product_for_id_random', always=True)
def curr_product_for_id_random_lookup(cls, v, values, **kwargs):
log.setLevel(logging.DEBUG)
log.debug(locals()) log.debug(locals())
if values['curr_product_for_id_random'] and values['curr_product_for_type']: if values['curr_product_for_id'] and values['curr_product_for_type']:
return redis_lookup_id_random(record_id_random=values['curr_product_for_id_random'], table_name=values['curr_product_for_type']) return lookup_id_random(record_id=values['curr_product_for_id'], table_name=values['curr_product_for_type'])
return None return None
# @validator('curr_product_for_id', always=True)
# def curr_product_for_id_lookup(cls, v, values, **kwargs):
# log.setLevel(logging.WARNING)
# log.debug(locals())
# if values['curr_product_for_id_random'] and values['curr_product_for_type']:
# return redis_lookup_id_random(record_id_random=values['curr_product_for_id_random'], table_name=values['curr_product_for_type'])
# return None
class Config: class Config:
underscore_attrs_are_private = True underscore_attrs_are_private = True
allow_population_by_field_name = True allow_population_by_field_name = True
fields = base_fields fields = base_fields
Order_Line_Base.update_forward_refs()

View File

@@ -52,6 +52,7 @@ class Person_Base(BaseModel):
full_name: Optional[str] full_name: Optional[str]
informal_full_name: Optional[str] informal_full_name: Optional[str]
last_first_name: Optional[str] last_first_name: Optional[str]
display_name: Optional[str]
title: Optional[str] title: Optional[str]

View File

@@ -185,7 +185,7 @@ async def get_order_obj(
inc_order_cfg = inc_order_cfg, inc_order_cfg = inc_order_cfg,
): ):
log.debug(order_obj) log.debug(order_obj)
data = order_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) data = order_obj.dict(by_alias=by_alias, exclude_unset=False) # NOTE NOTE NOTE NOTE exclude_unset is forced to False for now. Will return more fields than is ideal. Need to create another Order_Line_Base. Probably Order_Line_OUT_Base
return mk_resp(data=data) return mk_resp(data=data)
else: else:
return mk_resp(data=False, status_code=404) # Not Found return mk_resp(data=False, status_code=404) # Not Found