Skip to content

Commit

Permalink
use custom json encoder on SystemHistory.save to better handle serial…
Browse files Browse the repository at this point in the history
…ization edge cases
  • Loading branch information
adamsachs committed May 1, 2024
1 parent 8da13ca commit 091c69d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fides/api/models/system_history.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from json import dumps
from typing import Optional

from sqlalchemy import Column, ForeignKey, Index, String
Expand All @@ -6,8 +7,9 @@
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import Session

from fides.api.db.base_class import Base
from fides.api.db.base_class import Base, FidesBase
from fides.api.models.fides_user import FidesUser
from fides.api.util.cache import CustomJSONEncoder
from fides.config import get_config

CONFIG = get_config()
Expand Down Expand Up @@ -46,3 +48,9 @@ def edited_by(self) -> Optional[str]:
user: Optional[FidesUser] = FidesUser.get_by(db, field="id", value=self.user_id)

return user.username if user else self.user_id

def save(self, db: Session) -> FidesBase:
"""Overrides the base class save to ensure JSON fields are well-serialized"""
self.before = dumps(self.before, cls=CustomJSONEncoder)
self.after = dumps(self.after, cls=CustomJSONEncoder)
return super().save(db=db)

0 comments on commit 091c69d

Please sign in to comment.