Skip to content

Commit 9d30852

Browse files
authored
build: Relax pydantic version requirement (#332)
1 parent 19108dc commit 9d30852

File tree

11 files changed

+62
-47
lines changed

11 files changed

+62
-47
lines changed

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ install_requires =
3232
cryptography>=3.4.0
3333
httpcore<0.17.3
3434
httpx[http2]==0.24.0
35-
pydantic[dotenv]>=1.8.2,<2.0
35+
pydantic[dotenv]>=1.8.2,<3.0.0
3636
python-dateutil>=2.8.2
3737
readerwriterlock>=1.0.9
3838
sqlparse>=0.4.2
@@ -51,7 +51,7 @@ ciso8601 =
5151
dev =
5252
allure-pytest==2.*
5353
devtools==0.7.0
54-
mypy==0.910
54+
mypy==1.*
5555
pre-commit==2.15.0
5656
pyfakefs>=4.5.3
5757
pytest==7.2.0
@@ -71,6 +71,7 @@ firebolt = py.typed
7171
disallow_untyped_defs = True
7272
show_error_codes = True
7373
files = src/
74+
plugins = pydantic.mypy
7475

7576
[flake8]
7677
exclude = tests/*

src/firebolt/async_db/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def __exit__(
395395
self.close()
396396

397397
def __await__(self) -> Iterator:
398-
pass
398+
yield None
399399

400400
async def __aexit__(
401401
self, exc_type: type, exc_val: Exception, exc_tb: TracebackType

src/firebolt/client/auth/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from abc import abstractmethod
12
from time import time
23
from typing import AsyncGenerator, Generator, Optional
34

@@ -44,7 +45,7 @@ def copy(self) -> "Auth":
4445
Returns:
4546
Auth: Auth object
4647
"""
47-
return Auth(self._use_token_cache)
48+
return self.__class__(self._use_token_cache)
4849

4950
@property
5051
def token(self) -> Optional[str]:
@@ -103,6 +104,7 @@ def _cache_token(self) -> None:
103104
if self._token and self._expires:
104105
self._token_storage.cache_token(self._token, self._expires)
105106

107+
@abstractmethod
106108
def get_new_token_generator(self) -> Generator[Request, Response, None]:
107109
"""Generate requests needed to create a new token session."""
108110

src/firebolt/model/V1/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66

77
class FireboltBaseModel(BaseModel):
8+
9+
# Using Pydantic 1.* config class for backwards compatibility
810
class Config:
9-
allow_population_by_field_name = True
1011
extra = "forbid"
12+
allow_population_by_field_name = True # Pydantic 1.8
13+
populate_by_name = True # Pydantic 2.0
1114

1215
def jsonable_dict(self, *args: Any, **kwargs: Any) -> dict:
1316
"""

src/firebolt/model/V1/binding.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class Binding(FireboltBaseModel):
2121
is_default_engine: bool = Field(alias="engine_is_default")
2222

2323
# optional
24-
current_status: Optional[str]
25-
health_status: Optional[str]
26-
create_time: Optional[datetime]
27-
create_actor: Optional[str]
28-
last_update_time: Optional[datetime]
29-
last_update_actor: Optional[str]
30-
desired_status: Optional[str]
24+
current_status: Optional[str] = None
25+
health_status: Optional[str] = None
26+
create_time: Optional[datetime] = None
27+
create_actor: Optional[str] = None
28+
last_update_time: Optional[datetime] = None
29+
last_update_actor: Optional[str] = None
30+
desired_status: Optional[str] = None
3131

3232
@property
3333
def database_id(self) -> str:

src/firebolt/model/V1/database.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@ class Database(FireboltBaseModel):
4242
_service: DatabaseService = PrivateAttr()
4343

4444
# required
45-
name: str = Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")
45+
name: str = Field(min_length=1, max_length=255, pattern=r"^[0-9a-zA-Z_]+$")
4646
compute_region_key: RegionKey = Field(alias="compute_region_id")
4747

4848
# optional
49-
database_key: Optional[DatabaseKey] = Field(None, alias="id")
50-
description: Optional[str] = Field(None, max_length=255)
51-
emoji: Optional[str] = Field(None, max_length=255)
52-
current_status: Optional[str]
53-
health_status: Optional[str]
54-
data_size_full: Optional[int]
55-
data_size_compressed: Optional[int]
56-
is_system_database: Optional[bool]
57-
storage_bucket_name: Optional[str]
58-
create_time: Optional[datetime]
59-
create_actor: Optional[str]
60-
last_update_time: Optional[datetime]
61-
last_update_actor: Optional[str]
62-
desired_status: Optional[str]
49+
database_key: Optional[DatabaseKey] = Field(default=None, alias="id")
50+
description: Optional[str] = Field(default=None, max_length=255)
51+
emoji: Optional[str] = Field(default=None, max_length=255)
52+
current_status: Optional[str] = None
53+
health_status: Optional[str] = None
54+
data_size_full: Optional[int] = None
55+
data_size_compressed: Optional[int] = None
56+
is_system_database: Optional[bool] = None
57+
storage_bucket_name: Optional[str] = None
58+
create_time: Optional[datetime] = None
59+
create_actor: Optional[str] = None
60+
last_update_time: Optional[datetime] = None
61+
last_update_actor: Optional[str] = None
62+
desired_status: Optional[str] = None
6363

6464
@classmethod
6565
def parse_obj_with_service(
@@ -142,6 +142,7 @@ class _DatabaseUpdateRequest(FireboltBaseModel):
142142

143143
self.description = description
144144

145+
assert self.database_id is not None, "Database must have database_id"
145146
logger.info(
146147
f"Updating Database (database_id={self.database_id}, "
147148
f"name={self.name}, description={self.description})"

src/firebolt/model/V1/engine.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EngineSettings(FireboltBaseModel):
5050
"""
5151

5252
preset: str
53-
auto_stop_delay_duration: str = Field(regex=r"^[0-9]+[sm]$|^0$")
53+
auto_stop_delay_duration: str = Field(pattern=r"^[0-9]+[sm]$|^0$")
5454
minimum_logging_level: str
5555
is_read_only: bool
5656
warm_up: str
@@ -97,30 +97,30 @@ class Engine(FireboltBaseModel):
9797
_service: EngineService = PrivateAttr()
9898

9999
# required
100-
name: str = Field(min_length=1, max_length=255, regex=r"^[0-9a-zA-Z_]+$")
100+
name: str = Field(min_length=1, max_length=255, pattern=r"^[0-9a-zA-Z_]+$")
101101
compute_region_key: RegionKey = Field(alias="compute_region_id")
102102
settings: EngineSettings
103103

104104
# optional
105105
key: Optional[EngineKey] = Field(None, alias="id")
106-
description: Optional[str]
107-
emoji: Optional[str]
108-
current_status: Optional[EngineStatus]
109-
current_status_summary: Optional[EngineStatusSummary]
106+
description: Optional[str] = None
107+
emoji: Optional[str] = None
108+
current_status: Optional[EngineStatus] = None
109+
current_status_summary: Optional[EngineStatusSummary] = None
110110
latest_revision_key: Optional[EngineRevisionKey] = Field(
111111
None, alias="latest_revision_id"
112112
)
113-
endpoint: Optional[str]
113+
endpoint: Optional[str] = None
114114
endpoint_serving_revision_key: Optional[EngineRevisionKey] = Field(
115115
None, alias="endpoint_serving_revision_id"
116116
)
117-
create_time: Optional[datetime]
118-
create_actor: Optional[str]
119-
last_update_time: Optional[datetime]
120-
last_update_actor: Optional[str]
121-
last_use_time: Optional[datetime]
122-
desired_status: Optional[str]
123-
health_status: Optional[str]
117+
create_time: Optional[datetime] = None
118+
create_actor: Optional[str] = None
119+
last_update_time: Optional[datetime] = None
120+
last_update_actor: Optional[str] = None
121+
last_use_time: Optional[datetime] = None
122+
desired_status: Optional[str] = None
123+
health_status: Optional[str] = None
124124
endpoint_desired_revision_key: Optional[EngineRevisionKey] = Field(
125125
None, alias="endpoint_desired_revision_id"
126126
)

src/firebolt/model/V1/provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class Provider(FireboltBaseModel, frozen=True): # type: ignore
1111
name: str
1212

1313
# optional
14-
create_time: Optional[datetime]
15-
display_name: Optional[str]
16-
last_update_time: Optional[datetime]
14+
create_time: Optional[datetime] = None
15+
display_name: Optional[str] = None
16+
last_update_time: Optional[datetime] = None

src/firebolt/model/V1/region.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class Region(FireboltBaseModel):
1616
name: str
1717

1818
# optional
19-
display_name: Optional[str]
20-
create_time: Optional[datetime]
21-
last_update_time: Optional[datetime]
19+
display_name: Optional[str] = None
20+
create_time: Optional[datetime] = None
21+
last_update_time: Optional[datetime] = None

src/firebolt/service/V1/binding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def create(
125125
f"to Database (database_id={database.database_id}, "
126126
f"name={database.name})"
127127
)
128+
assert database.database_id is not None, "Database must have database_id"
128129
binding = Binding(
129130
binding_key=BindingKey(
130131
account_id=self.account_id,

0 commit comments

Comments
 (0)