Skip to content

Commit

Permalink
Merge pull request #1360 from phenobarbital/py313-support
Browse files Browse the repository at this point in the history
Add conversion of enum in values on Model methods insert and update
  • Loading branch information
phenobarbital authored Dec 19, 2024
2 parents fd19461 + baa5628 commit 335524c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions asyncdb/drivers/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import asyncio
from enum import Enum
import os
import ssl
import time
Expand Down Expand Up @@ -1178,6 +1179,8 @@ async def _insert_(self, _model: Model, **kwargs): # pylint: disable=W0613
value = getattr(value, name)
except AttributeError:
value = None
elif isinstance(value, Enum):
value = value.value
source.append(value)
cols.append(column)
n += 1
Expand Down Expand Up @@ -1299,6 +1302,8 @@ async def _update_(self, _model: Model, **kwargs): # pylint: disable=W0613
value = getattr(value, name)
except AttributeError:
value = None
elif isinstance(value, Enum):
value = value.value
cols.append("{} = {}".format(name, "${}".format(n))) # pylint: disable=C0209
source.append(value)
n += 1
Expand Down
3 changes: 3 additions & 0 deletions asyncdb/interfaces/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Any, List
from abc import ABC, abstractmethod
import uuid
Expand Down Expand Up @@ -122,6 +123,8 @@ def _get_value(self, field: Field, value: Any) -> Any:
new_val = None
elif callable(datatype) and value is None:
new_val = None
elif isinstance(value, Enum):
new_val = value.value
else:
new_val = value
return new_val
Expand Down
2 changes: 1 addition & 1 deletion asyncdb/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = "asyncdb"
__description__ = "Library for Asynchronous data source connections \
Collection of asyncio drivers."
__version__ = "2.9.9"
__version__ = "2.9.10"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def readme():
"aioboto3==13.2.0"
],
"bigquery": [
"google-cloud-bigquery==3.25.0",
"google-cloud-bigquery==3.27.0",
"google-cloud-bigquery-storage==2.27.0",
"pandas-gbq==0.24.0",
"google-cloud-storage>=2.17.0"
],
Expand Down

0 comments on commit 335524c

Please sign in to comment.