Skip to content

Commit

Permalink
fix: omit undefined type in record.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrckd committed Sep 12, 2024
1 parent 8932e39 commit 472465c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"UserRecord", ["id", "tchap_user", "status", "domain", "n_questions", "last_activity"]
)

def to_record(_id: str, data: dict):
"""Dict to a grist record"""
return UserRecord(
**{"id": _id, **{k: v for k, v in data.items() if k in UserRecord._fields}}
)



# from grist_api import GristDocAPI => is not async
class AsyncGristDocAPI:
Expand Down Expand Up @@ -45,7 +52,7 @@ async def fetch_table(self, table_id, filters=None) -> list[UserRecord]:

if not result["records"]:
return []
records = [UserRecord(**{"id": r["id"], **r["fields"]}) for r in result["records"]]
records = [to_record(r["id"], r["fields"]) for r in result["records"]]
return records

async def add_records(self, table_id, records):
Expand Down Expand Up @@ -162,7 +169,8 @@ async def add_pending_user(self, config, username) -> bool:
results = await self.iam_client.add_records(self.users_table_name, [record])

# Update the {not_allowed} table
records = [UserRecord(**{"id": results["records"][0]["id"], **record})]
records = [to_record(results["records"][0]["id"], record)]

for r in records:
self.users_not_allowed[r.tchap_user] = r

Expand Down

0 comments on commit 472465c

Please sign in to comment.