From 5f34337fb40bb5d6d484f8907285eb249861b607 Mon Sep 17 00:00:00 2001 From: inexcode Date: Mon, 15 Aug 2022 23:37:34 +0400 Subject: [PATCH] Serialize custom types --- selfprivacy_api/jobs/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/selfprivacy_api/jobs/__init__.py b/selfprivacy_api/jobs/__init__.py index 12430ee..e218d10 100644 --- a/selfprivacy_api/jobs/__init__.py +++ b/selfprivacy_api/jobs/__init__.py @@ -33,7 +33,6 @@ class JobStatus(Enum): """ Status of a job. """ - CREATED = "CREATED" RUNNING = "RUNNING" FINISHED = "FINISHED" @@ -44,8 +43,7 @@ class Job(BaseModel): """ Job class. """ - - uid: str = uuid.uuid4().urn + uid: UUID = uuid.uuid4() name: str description: str status: JobStatus @@ -118,10 +116,10 @@ class Jobs: ) with WriteUserData(UserDataFiles.JOBS) as user_data: try: - user_data.append(job.dict()) + user_data.append(json.loads(job.json())) except json.decoder.JSONDecodeError: user_data = [] - user_data.append(job.dict()) + user_data.append(json.loads(job.json())) return job def remove(self, job: Job) -> None: @@ -162,7 +160,7 @@ class Jobs: with WriteUserData(UserDataFiles.JOBS) as user_data: user_data = [x for x in user_data if x["uid"] != job.uid] - user_data.append(job.dict()) + user_data.append(json.loads(job.json())) return job