alchemy flush and save functions updated
This commit is contained in:
@@ -24,13 +24,14 @@ class FilterAttributes:
|
||||
FilterModel = ListOptions
|
||||
|
||||
def flush(self):
|
||||
from fastapi import status
|
||||
"""Flush the current session."""
|
||||
try:
|
||||
self.__session__.add(self)
|
||||
self.__session__.flush()
|
||||
except SQLAlchemyError as e:
|
||||
self.raise_http_exception(
|
||||
status_code="HTTP_304_NOT_MODIFIED",
|
||||
status_code="HTTP_400_BAD_REQUEST",
|
||||
error_case=e.__class__.__name__,
|
||||
data={},
|
||||
message=str(e.__context__).split("\n")[0],
|
||||
@@ -48,7 +49,7 @@ class FilterAttributes:
|
||||
cls.__session__.commit()
|
||||
except SQLAlchemyError as e:
|
||||
cls.raise_http_exception(
|
||||
status_code="HTTP_304_NOT_MODIFIED",
|
||||
status_code="HTTP_400_BAD_REQUEST",
|
||||
error_case=e.__class__.__name__,
|
||||
data={},
|
||||
message=str(e.__context__).split("\n")[0],
|
||||
@@ -92,10 +93,11 @@ class FilterAttributes:
|
||||
|
||||
@classmethod
|
||||
def add_new_arg_to_args(cls, args_list, argument, value):
|
||||
new_arg_list = list(
|
||||
new_arg_list = list(set(
|
||||
args_ for args_ in list(args_list) if isinstance(args_, SQLColumnExpression)
|
||||
)
|
||||
if not any(True for arg in new_arg_list if arg.left.key == argument):
|
||||
))
|
||||
arg_left = lambda arg_obj: getattr(getattr(arg_obj, "left", None), 'key', None)
|
||||
if not any(True for arg in new_arg_list if arg_left(arg_obj=arg) == argument):
|
||||
new_arg_list.append(value)
|
||||
return tuple(new_arg_list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user