Skip to content

Commit

Permalink
fix auditlog refs (ethyca#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Preston authored and Adam Sachs committed May 17, 2022
1 parent 35cd3db commit c4d368e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/fidesops/models/fidesops_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from fidesops.core.config import config
from fidesops.db.base_class import Base
from fidesops.models.audit_log import AuditLog
from fidesops.util.cryptographic_util import generate_salt, hash_with_salt


Expand All @@ -20,6 +21,16 @@ class FidesopsUser(Base):
last_login_at = Column(DateTime(timezone=True), nullable=True)
password_reset_at = Column(DateTime(timezone=True), nullable=True)

# passive_deletes="all" prevents audit logs from having their privacy_request_id set to null when
# a privacy_request is deleted. We want to retain for record-keeping.
audit_logs = relationship(
AuditLog,
backref="fidesops_user",
lazy="dynamic",
passive_deletes="all",
primaryjoin="foreign(AuditLog.user_id)==FidesopsUser.id",
)

client = relationship(
"ClientDetail", backref="user", cascade="all, delete", uselist=False
)
Expand Down
3 changes: 2 additions & 1 deletion src/fidesops/models/privacy_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Base,
FidesopsBase,
)
from fidesops.models.audit_log import AuditLog
from fidesops.models.client import ClientDetail
from fidesops.models.fidesops_user import FidesopsUser
from fidesops.models.policy import (
Expand Down Expand Up @@ -134,7 +135,7 @@ class PrivacyRequest(Base):
# passive_deletes="all" prevents audit logs from having their privacy_request_id set to null when
# a privacy_request is deleted. We want to retain for record-keeping.
audit_logs = relationship(
"AuditLog",
AuditLog,
backref="privacy_request",
lazy="dynamic",
passive_deletes="all",
Expand Down

0 comments on commit c4d368e

Please sign in to comment.