Skip to content

Commit 73ee6e2

Browse files
authored
fix(backend): Unbreak UserIntegrations parsing for missing None values (#9994)
Makes all optional fields on `Credentials` models actually optional, and sets `exclude_none=True` on the corresponding `model_dump`. This is a hotfix: after running the `aryshare-revid` branch on the dev deployment, there is some data in the DB that isn't valid for the `UserIntegrations` model on the `dev` branch (see [here](#9946 (comment))). ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] This fix worked on the `aryshare-revid` branch: 52b6d96
1 parent f466b01 commit 73ee6e2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

autogpt_platform/backend/backend/data/model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def SchemaField(
189189
class _BaseCredentials(BaseModel):
190190
id: str = Field(default_factory=lambda: str(uuid4()))
191191
provider: str
192-
title: Optional[str]
192+
title: Optional[str] = None
193193

194194
@field_serializer("*")
195195
def dump_secret_strings(value: Any, _info):
@@ -200,13 +200,13 @@ def dump_secret_strings(value: Any, _info):
200200

201201
class OAuth2Credentials(_BaseCredentials):
202202
type: Literal["oauth2"] = "oauth2"
203-
username: Optional[str]
203+
username: Optional[str] = None
204204
"""Username of the third-party service user that these credentials belong to"""
205205
access_token: SecretStr
206-
access_token_expires_at: Optional[int]
206+
access_token_expires_at: Optional[int] = None
207207
"""Unix timestamp (seconds) indicating when the access token expires (if at all)"""
208-
refresh_token: Optional[SecretStr]
209-
refresh_token_expires_at: Optional[int]
208+
refresh_token: Optional[SecretStr] = None
209+
refresh_token_expires_at: Optional[int] = None
210210
"""Unix timestamp (seconds) indicating when the refresh token expires (if at all)"""
211211
scopes: list[str]
212212
metadata: dict[str, Any] = Field(default_factory=dict)

autogpt_platform/backend/backend/data/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def get_user_integrations(user_id: str) -> UserIntegrations:
124124

125125

126126
async def update_user_integrations(user_id: str, data: UserIntegrations):
127-
encrypted_data = JSONCryptor().encrypt(data.model_dump())
127+
encrypted_data = JSONCryptor().encrypt(data.model_dump(exclude_none=True))
128128
await User.prisma().update(
129129
where={"id": user_id},
130130
data={"integrations": encrypted_data},

0 commit comments

Comments
 (0)