ethyca-fides 2.57.1b4__py2.py3-none-any.whl → 2.57.1b5__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/METADATA +1 -1
  2. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/RECORD +92 -88
  3. fides/_version.py +3 -3
  4. fides/api/models/privacy_request/__init__.py +13 -7
  5. fides/api/models/privacy_request/consent.py +2 -4
  6. fides/api/models/privacy_request/execution_log.py +108 -0
  7. fides/api/models/privacy_request/privacy_request.py +15 -544
  8. fides/api/models/privacy_request/provided_identity.py +149 -0
  9. fides/api/models/privacy_request/request_task.py +284 -0
  10. fides/api/models/privacy_request/webhook.py +94 -0
  11. fides/api/oauth/jwt.py +18 -0
  12. fides/ui-build/static/admin/404.html +1 -1
  13. fides/ui-build/static/admin/add-systems/manual.html +1 -1
  14. fides/ui-build/static/admin/add-systems/multiple.html +1 -1
  15. fides/ui-build/static/admin/add-systems.html +1 -1
  16. fides/ui-build/static/admin/ant-poc.html +1 -1
  17. fides/ui-build/static/admin/consent/configure/add-vendors.html +1 -1
  18. fides/ui-build/static/admin/consent/configure.html +1 -1
  19. fides/ui-build/static/admin/consent/privacy-experience/[id].html +1 -1
  20. fides/ui-build/static/admin/consent/privacy-experience/new.html +1 -1
  21. fides/ui-build/static/admin/consent/privacy-experience.html +1 -1
  22. fides/ui-build/static/admin/consent/privacy-notices/[id].html +1 -1
  23. fides/ui-build/static/admin/consent/privacy-notices/new.html +1 -1
  24. fides/ui-build/static/admin/consent/privacy-notices.html +1 -1
  25. fides/ui-build/static/admin/consent/properties.html +1 -1
  26. fides/ui-build/static/admin/consent/reporting.html +1 -1
  27. fides/ui-build/static/admin/consent.html +1 -1
  28. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn]/[resourceUrn].html +1 -1
  29. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn].html +1 -1
  30. fides/ui-build/static/admin/data-catalog/[systemId]/projects.html +1 -1
  31. fides/ui-build/static/admin/data-catalog/[systemId]/resources/[resourceUrn].html +1 -1
  32. fides/ui-build/static/admin/data-catalog/[systemId]/resources.html +1 -1
  33. fides/ui-build/static/admin/data-catalog.html +1 -1
  34. fides/ui-build/static/admin/data-discovery/action-center/[monitorId]/[systemId].html +1 -1
  35. fides/ui-build/static/admin/data-discovery/action-center/[monitorId].html +1 -1
  36. fides/ui-build/static/admin/data-discovery/action-center.html +1 -1
  37. fides/ui-build/static/admin/data-discovery/activity.html +1 -1
  38. fides/ui-build/static/admin/data-discovery/detection/[resourceUrn].html +1 -1
  39. fides/ui-build/static/admin/data-discovery/detection.html +1 -1
  40. fides/ui-build/static/admin/data-discovery/discovery/[resourceUrn].html +1 -1
  41. fides/ui-build/static/admin/data-discovery/discovery.html +1 -1
  42. fides/ui-build/static/admin/datamap.html +1 -1
  43. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName]/[...subfieldNames].html +1 -1
  44. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName].html +1 -1
  45. fides/ui-build/static/admin/dataset/[datasetId].html +1 -1
  46. fides/ui-build/static/admin/dataset/new.html +1 -1
  47. fides/ui-build/static/admin/dataset.html +1 -1
  48. fides/ui-build/static/admin/datastore-connection/[id].html +1 -1
  49. fides/ui-build/static/admin/datastore-connection/new.html +1 -1
  50. fides/ui-build/static/admin/datastore-connection.html +1 -1
  51. fides/ui-build/static/admin/index.html +1 -1
  52. fides/ui-build/static/admin/integrations/[id].html +1 -1
  53. fides/ui-build/static/admin/integrations.html +1 -1
  54. fides/ui-build/static/admin/lib/fides-headless.js +1 -1
  55. fides/ui-build/static/admin/lib/fides-tcf.js +3 -3
  56. fides/ui-build/static/admin/lib/fides.js +2 -2
  57. fides/ui-build/static/admin/login/[provider].html +1 -1
  58. fides/ui-build/static/admin/login.html +1 -1
  59. fides/ui-build/static/admin/messaging/[id].html +1 -1
  60. fides/ui-build/static/admin/messaging/add-template.html +1 -1
  61. fides/ui-build/static/admin/messaging.html +1 -1
  62. fides/ui-build/static/admin/privacy-requests/[id].html +1 -1
  63. fides/ui-build/static/admin/privacy-requests/configure/messaging.html +1 -1
  64. fides/ui-build/static/admin/privacy-requests/configure/storage.html +1 -1
  65. fides/ui-build/static/admin/privacy-requests/configure.html +1 -1
  66. fides/ui-build/static/admin/privacy-requests.html +1 -1
  67. fides/ui-build/static/admin/properties/[id].html +1 -1
  68. fides/ui-build/static/admin/properties/add-property.html +1 -1
  69. fides/ui-build/static/admin/properties.html +1 -1
  70. fides/ui-build/static/admin/reporting/datamap.html +1 -1
  71. fides/ui-build/static/admin/settings/about.html +1 -1
  72. fides/ui-build/static/admin/settings/consent.html +1 -1
  73. fides/ui-build/static/admin/settings/custom-fields.html +1 -1
  74. fides/ui-build/static/admin/settings/domain-records.html +1 -1
  75. fides/ui-build/static/admin/settings/domains.html +1 -1
  76. fides/ui-build/static/admin/settings/email-templates.html +1 -1
  77. fides/ui-build/static/admin/settings/locations.html +1 -1
  78. fides/ui-build/static/admin/settings/organization.html +1 -1
  79. fides/ui-build/static/admin/settings/regulations.html +1 -1
  80. fides/ui-build/static/admin/systems/configure/[id]/test-datasets.html +1 -1
  81. fides/ui-build/static/admin/systems/configure/[id].html +1 -1
  82. fides/ui-build/static/admin/systems.html +1 -1
  83. fides/ui-build/static/admin/taxonomy.html +1 -1
  84. fides/ui-build/static/admin/user-management/new.html +1 -1
  85. fides/ui-build/static/admin/user-management/profile/[id].html +1 -1
  86. fides/ui-build/static/admin/user-management.html +1 -1
  87. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/LICENSE +0 -0
  88. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/WHEEL +0 -0
  89. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/entry_points.txt +0 -0
  90. {ethyca_fides-2.57.1b4.dist-info → ethyca_fides-2.57.1b5.dist-info}/top_level.txt +0 -0
  91. /fides/ui-build/static/admin/_next/static/{sDpAo7vHYkuZ5moMST2L3 → nO-B4awcqTzE1AwRkxKgF}/_buildManifest.js +0 -0
  92. /fides/ui-build/static/admin/_next/static/{sDpAo7vHYkuZ5moMST2L3 → nO-B4awcqTzE1AwRkxKgF}/_ssgManifest.js +0 -0
@@ -4,19 +4,16 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
  from datetime import datetime, timedelta
7
- from enum import Enum as EnumType
8
- from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple, Union
7
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Union
9
8
 
10
9
  from celery.result import AsyncResult
11
10
  from loguru import logger
12
- from pydantic import BaseModel, ConfigDict
13
11
  from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
14
12
  from sqlalchemy.dialects.postgresql import JSONB
15
13
  from sqlalchemy.ext.declarative import declared_attr
16
14
  from sqlalchemy.ext.mutable import MutableDict, MutableList
17
15
  from sqlalchemy.orm import Query, RelationshipProperty, Session, backref, relationship
18
16
  from sqlalchemy.orm.dynamic import AppenderQuery
19
- from sqlalchemy.sql import text
20
17
  from sqlalchemy_utils.types.encrypted.encrypted_type import (
21
18
  AesGcmEngine,
22
19
  StringEncryptedType,
@@ -56,14 +53,21 @@ from fides.api.models.pre_approval_webhook import (
56
53
  PreApprovalWebhook,
57
54
  PreApprovalWebhookReply,
58
55
  )
59
- from fides.api.oauth.jwt import generate_jwe
60
- from fides.api.schemas.base_class import FidesSchema
61
- from fides.api.schemas.drp_privacy_request import DrpPrivacyRequestCreate
62
- from fides.api.schemas.external_https import (
63
- RequestTaskJWE,
64
- SecondPartyResponseFormat,
65
- WebhookJWE,
56
+ from fides.api.models.privacy_request.execution_log import (
57
+ COMPLETED_EXECUTION_LOG_STATUSES,
58
+ EXITED_EXECUTION_LOG_STATUSES,
59
+ ExecutionLog,
60
+ )
61
+ from fides.api.models.privacy_request.provided_identity import ProvidedIdentity
62
+ from fides.api.models.privacy_request.request_task import RequestTask
63
+ from fides.api.models.privacy_request.webhook import (
64
+ CallbackType,
65
+ SecondPartyRequestFormat,
66
+ generate_request_callback_pre_approval_jwe,
67
+ generate_request_callback_resume_jwe,
66
68
  )
69
+ from fides.api.schemas.drp_privacy_request import DrpPrivacyRequestCreate
70
+ from fides.api.schemas.external_https import SecondPartyResponseFormat
67
71
  from fides.api.schemas.masking.masking_secrets import MaskingSecretCache
68
72
  from fides.api.schemas.policy import ActionType, CurrentStep
69
73
  from fides.api.schemas.privacy_request import (
@@ -80,7 +84,6 @@ from fides.api.schemas.redis_cache import Identity, LabeledIdentity, MultiValue
80
84
  from fides.api.tasks import celery_app
81
85
  from fides.api.util.cache import (
82
86
  FidesopsRedis,
83
- celery_tasks_in_flight,
84
87
  get_all_cache_keys_for_privacy_request,
85
88
  get_async_task_tracking_cache_key,
86
89
  get_cache,
@@ -97,10 +100,6 @@ from fides.api.util.decrypted_identity_automaton import DecryptedIdentityAutomat
97
100
  from fides.api.util.identity_verification import IdentityVerificationMixin
98
101
  from fides.api.util.logger import Pii
99
102
  from fides.api.util.logger_context_utils import Contextualizable, LoggerContextKeys
100
- from fides.common.api.scope_registry import (
101
- PRIVACY_REQUEST_CALLBACK_RESUME,
102
- PRIVACY_REQUEST_REVIEW,
103
- )
104
103
  from fides.config import CONFIG
105
104
 
106
105
  if TYPE_CHECKING:
@@ -109,89 +108,6 @@ if TYPE_CHECKING:
109
108
  ConsentRequest,
110
109
  )
111
110
 
112
- # Locations from which privacy request execution can be resumed, in order.
113
- EXECUTION_CHECKPOINTS = [
114
- CurrentStep.pre_webhooks,
115
- CurrentStep.access,
116
- CurrentStep.upload_access,
117
- CurrentStep.erasure,
118
- CurrentStep.finalize_erasure,
119
- CurrentStep.consent,
120
- CurrentStep.finalize_consent,
121
- CurrentStep.email_post_send,
122
- CurrentStep.post_webhooks,
123
- ]
124
-
125
-
126
- class CallbackType(EnumType):
127
- """We currently have three types of Webhooks: pre-approval, pre (-execution), post (-execution)"""
128
-
129
- pre_approval = "pre_approval"
130
- pre = "pre" # pre-execution
131
- post = "post" # post-execution
132
-
133
-
134
- class SecondPartyRequestFormat(BaseModel):
135
- """
136
- The request body we will use when calling a user's HTTP endpoint from fides.api
137
- This class is defined here to avoid circular import issues between this file and
138
- models.policy
139
- """
140
-
141
- privacy_request_id: str
142
- privacy_request_status: PrivacyRequestStatus
143
- direction: WebhookDirection
144
- callback_type: CallbackType
145
- identity: Identity
146
- policy_action: Optional[ActionType] = None
147
- model_config = ConfigDict(use_enum_values=True)
148
-
149
-
150
- def generate_request_callback_resume_jwe(webhook: PolicyPreWebhook) -> str:
151
- """
152
- Generate a JWE to be used to resume privacy request execution.
153
- """
154
- jwe = WebhookJWE(
155
- webhook_id=webhook.id,
156
- scopes=[PRIVACY_REQUEST_CALLBACK_RESUME],
157
- iat=datetime.now().isoformat(),
158
- )
159
- return generate_jwe(
160
- json.dumps(jwe.model_dump(mode="json")),
161
- CONFIG.security.app_encryption_key,
162
- )
163
-
164
-
165
- def generate_request_callback_pre_approval_jwe(webhook: PreApprovalWebhook) -> str:
166
- """
167
- Generate a JWE to be used to mark privacy requests as eligible / not-eligible for pre approval.
168
- """
169
- jwe = WebhookJWE(
170
- webhook_id=webhook.id,
171
- scopes=[PRIVACY_REQUEST_REVIEW],
172
- iat=datetime.now().isoformat(),
173
- )
174
- return generate_jwe(
175
- json.dumps(jwe.model_dump(mode="json")),
176
- CONFIG.security.app_encryption_key,
177
- )
178
-
179
-
180
- def generate_request_task_callback_jwe(request_task: RequestTask) -> str:
181
- """
182
- Generate a JWE to be used to resume privacy request execution when a
183
- callback endpoint is hit for a RequestTask
184
- """
185
- jwe = RequestTaskJWE(
186
- request_task_id=request_task.id,
187
- scopes=[PRIVACY_REQUEST_CALLBACK_RESUME],
188
- iat=datetime.now().isoformat(),
189
- )
190
- return generate_jwe(
191
- json.dumps(jwe.model_dump(mode="json")),
192
- CONFIG.security.app_encryption_key,
193
- )
194
-
195
111
 
196
112
  class PrivacyRequest(
197
113
  IdentityVerificationMixin, DecryptedIdentityAutomatonMixin, Contextualizable, Base
@@ -1365,128 +1281,6 @@ class PrivacyRequestNotifications(Base):
1365
1281
  notify_after_failures = Column(Integer, nullable=False)
1366
1282
 
1367
1283
 
1368
- class ProvidedIdentityType(EnumType):
1369
- """Enum for privacy request identity types"""
1370
-
1371
- email = "email"
1372
- phone_number = "phone_number"
1373
- ga_client_id = "ga_client_id"
1374
- ljt_readerID = "ljt_readerID"
1375
- fides_user_device_id = "fides_user_device_id"
1376
- external_id = "external_id"
1377
-
1378
-
1379
- class ProvidedIdentity(HashMigrationMixin, Base): # pylint: disable=R0904
1380
- """
1381
- A table for storing identity fields and values provided at privacy request
1382
- creation time.
1383
- """
1384
-
1385
- privacy_request_id = Column(
1386
- String,
1387
- ForeignKey(
1388
- PrivacyRequest.id_field_path, ondelete="CASCADE", onupdate="CASCADE"
1389
- ),
1390
- )
1391
- privacy_request = relationship(
1392
- PrivacyRequest,
1393
- backref="provided_identities",
1394
- ) # Which privacy request this identity belongs to
1395
-
1396
- field_name = Column(
1397
- String,
1398
- index=False,
1399
- nullable=False,
1400
- )
1401
- field_label = Column(
1402
- String,
1403
- index=False,
1404
- nullable=True,
1405
- )
1406
- hashed_value = Column(
1407
- String,
1408
- index=True,
1409
- unique=False,
1410
- nullable=True,
1411
- ) # This field is used as a blind index for exact match searches
1412
- encrypted_value = Column(
1413
- MutableDict.as_mutable(
1414
- StringEncryptedType(
1415
- JSONTypeOverride,
1416
- CONFIG.security.app_encryption_key,
1417
- AesGcmEngine,
1418
- "pkcs5",
1419
- )
1420
- ),
1421
- nullable=True,
1422
- ) # Type bytea in the db
1423
- consent = relationship(
1424
- "Consent", back_populates="provided_identity", cascade="delete, delete-orphan"
1425
- )
1426
- consent_request = relationship(
1427
- "ConsentRequest",
1428
- back_populates="provided_identity",
1429
- cascade="delete, delete-orphan",
1430
- )
1431
-
1432
- @classmethod
1433
- def bcrypt_hash_value(
1434
- cls,
1435
- value: MultiValue,
1436
- encoding: str = "UTF-8",
1437
- ) -> str:
1438
- """
1439
- Temporary function used to hash values to the previously used bcrypt hashes.
1440
- This can be removed once the bcrypt to SHA-256 migration is complete.
1441
- """
1442
-
1443
- SALT = "$2b$12$UErimNtlsE6qgYf2BrI1Du"
1444
- value_str = str(value)
1445
- hashed_value = hash_credential_with_salt(
1446
- value_str.encode(encoding),
1447
- SALT.encode(encoding),
1448
- )
1449
- return hashed_value
1450
-
1451
- @classmethod
1452
- def hash_value(
1453
- cls,
1454
- value: MultiValue,
1455
- encoding: str = "UTF-8",
1456
- ) -> str:
1457
- """Utility function to hash the value with a generated salt"""
1458
- SALT = get_identity_salt()
1459
- value_str = str(value)
1460
- hashed_value = hash_value_with_salt(
1461
- value_str.encode(encoding),
1462
- SALT.encode(encoding),
1463
- )
1464
- return hashed_value
1465
-
1466
- def migrate_hashed_fields(self) -> None:
1467
- if value := self.encrypted_value.get("value"):
1468
- self.hashed_value = self.hash_value(value)
1469
- self.is_hash_migrated = True
1470
-
1471
- def as_identity_schema(self) -> Identity:
1472
- """Creates an Identity schema from a ProvidedIdentity record in the application DB."""
1473
-
1474
- identity_dict = {}
1475
- if any(
1476
- [
1477
- not self.field_name,
1478
- not self.encrypted_value,
1479
- ]
1480
- ):
1481
- return Identity()
1482
-
1483
- value = self.encrypted_value.get("value") # type:ignore
1484
- if self.field_label:
1485
- value = LabeledIdentity(label=self.field_label, value=value)
1486
- identity_dict[self.field_name] = value
1487
- return Identity(**identity_dict)
1488
-
1489
-
1490
1284
  class CustomPrivacyRequestField(HashMigrationMixin, Base):
1491
1285
  @declared_attr
1492
1286
  def __tablename__(self) -> str:
@@ -1632,86 +1426,6 @@ def get_action_required_details(
1632
1426
  return None
1633
1427
 
1634
1428
 
1635
- COMPLETED_EXECUTION_LOG_STATUSES = [
1636
- ExecutionLogStatus.complete,
1637
- ExecutionLogStatus.skipped,
1638
- ]
1639
- EXITED_EXECUTION_LOG_STATUSES = [
1640
- ExecutionLogStatus.complete,
1641
- ExecutionLogStatus.error,
1642
- ExecutionLogStatus.skipped,
1643
- ]
1644
-
1645
-
1646
- class ExecutionLog(Base):
1647
- """
1648
- Stores the individual execution logs associated with a PrivacyRequest.
1649
-
1650
- Execution logs contain information about the individual queries as they progress through the workflow
1651
- generated by the query builder.
1652
- """
1653
-
1654
- connection_key = Column(String, index=True)
1655
- # Name of the fides-annotated dataset, for example: my-mongo-db
1656
- dataset_name = Column(String, index=True)
1657
- # Name of the particular collection or table affected
1658
- collection_name = Column(String, index=True)
1659
- # A JSON Array describing affected fields along with their data categories and paths
1660
- fields_affected = Column(MutableList.as_mutable(JSONB), nullable=True)
1661
- # Contains info, warning, or error messages
1662
- message = Column(String)
1663
- action_type = Column(
1664
- EnumColumn(ActionType),
1665
- index=True,
1666
- nullable=False,
1667
- )
1668
- status = Column(
1669
- EnumColumn(
1670
- ExecutionLogStatus,
1671
- native_enum=True,
1672
- values_callable=lambda x: [
1673
- i.value for i in x
1674
- ], # Using ExecutionLogStatus values in database, even though app is using the names.
1675
- ),
1676
- index=True,
1677
- nullable=False,
1678
- )
1679
-
1680
- privacy_request_id = Column(
1681
- String,
1682
- nullable=False,
1683
- index=True,
1684
- )
1685
-
1686
- # Use clock_timestamp() instead of NOW() to get the actual current time at row creation,
1687
- # regardless of transaction state. This prevents timestamp caching within transactions
1688
- # and ensures more accurate creation times.
1689
- # https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
1690
-
1691
- created_at = Column(
1692
- DateTime(timezone=True), server_default=text("clock_timestamp()")
1693
- )
1694
- updated_at = Column(
1695
- DateTime(timezone=True),
1696
- server_default=text("clock_timestamp()"),
1697
- onupdate=text("clock_timestamp()"),
1698
- )
1699
-
1700
-
1701
- def can_run_checkpoint(
1702
- request_checkpoint: CurrentStep, from_checkpoint: Optional[CurrentStep] = None
1703
- ) -> bool:
1704
- """Determine whether we should run a specific checkpoint in privacy request execution
1705
-
1706
- If there's no from_checkpoint specified we should always run the current checkpoint.
1707
- """
1708
- if not from_checkpoint:
1709
- return True
1710
- return EXECUTION_CHECKPOINTS.index(
1711
- request_checkpoint
1712
- ) >= EXECUTION_CHECKPOINTS.index(from_checkpoint)
1713
-
1714
-
1715
1429
  def _parse_cache_to_checkpoint_action_required(
1716
1430
  cache: dict[str, Any]
1717
1431
  ) -> CheckpointActionRequired:
@@ -1733,246 +1447,3 @@ def _parse_cache_to_checkpoint_action_required(
1733
1447
  collection=collection,
1734
1448
  action_needed=action_needed,
1735
1449
  )
1736
-
1737
-
1738
- class TraversalDetails(FidesSchema):
1739
- """Schema to format saving pre-calculated traversal details on RequestTask.traversal_details"""
1740
-
1741
- dataset_connection_key: str
1742
- incoming_edges: List[Tuple[str, str]]
1743
- outgoing_edges: List[Tuple[str, str]]
1744
- input_keys: List[str]
1745
- skipped_nodes: Optional[List[Tuple[str, str]]] = None
1746
-
1747
- # TODO: remove this method once we support custom request fields in DSR graph.
1748
- @classmethod
1749
- def create_empty_traversal(cls, connection_key: str) -> TraversalDetails:
1750
- """
1751
- Creates an "empty" TraversalDetails object that only has the dataset connection key set.
1752
- This is a bit of a hacky workaround needed to implement the Dynamic Erasure Emails feature,
1753
- but we should no longer need it once the custom_request_fields are included in our graph
1754
- traversal
1755
- """
1756
- return cls(
1757
- dataset_connection_key=connection_key,
1758
- incoming_edges=[],
1759
- outgoing_edges=[],
1760
- input_keys=[],
1761
- skipped_nodes=[],
1762
- )
1763
-
1764
-
1765
- class RequestTask(Base):
1766
- """
1767
- An individual Task for a Privacy Request.
1768
-
1769
- When we execute a PrivacyRequest, we build a graph by combining the current datasets with the identity data
1770
- and we save the nodes (collections) in the graph as Request Tasks.
1771
-
1772
- Currently, we build access, erasure, and consent Request Tasks.
1773
- """
1774
-
1775
- privacy_request_id = Column(
1776
- String,
1777
- ForeignKey(PrivacyRequest.id_field_path, ondelete="SET NULL"),
1778
- nullable=True,
1779
- index=True,
1780
- )
1781
-
1782
- # Identifiers of this request task
1783
- collection_address = Column(
1784
- String, nullable=False, index=True
1785
- ) # Of the format dataset_name:collection_name for convenience
1786
- dataset_name = Column(String, nullable=False, index=True)
1787
- collection_name = Column(String, nullable=False, index=True)
1788
- action_type = Column(EnumColumn(ActionType), nullable=False, index=True)
1789
-
1790
- # Note that RequestTasks share statuses with ExecutionLogs. When a RequestTask changes state, an ExecutionLog
1791
- # is also created with that state. These are tied tightly together in GraphTask.
1792
- status = Column(
1793
- EnumColumn(
1794
- ExecutionLogStatus,
1795
- native_enum=False,
1796
- values_callable=lambda x: [
1797
- i.value for i in x
1798
- ], # Using ExecutionLogStatus values in database, even though app is using the names.
1799
- ), # character varying in database
1800
- index=True,
1801
- nullable=False,
1802
- )
1803
-
1804
- upstream_tasks = Column(
1805
- MutableList.as_mutable(JSONB)
1806
- ) # List of collection address strings
1807
- downstream_tasks = Column(
1808
- MutableList.as_mutable(JSONB)
1809
- ) # List of collection address strings
1810
- all_descendant_tasks = Column(
1811
- MutableList.as_mutable(JSONB)
1812
- ) # All tasks that can be reached by the current task. This is useful when this task fails,
1813
- # and we can mark every single one of these as failed.
1814
-
1815
- # Raw data retrieved from an access request is stored here. This contains all of the
1816
- # intermediate data we retrieved, needed for downstream tasks, but hasn't been filtered
1817
- # by data category for the end user.
1818
- access_data = Column( # An encrypted JSON String - saved as a list of Rows
1819
- StringEncryptedType(
1820
- type_in=JSONTypeOverride,
1821
- key=CONFIG.security.app_encryption_key,
1822
- engine=AesGcmEngine,
1823
- padding="pkcs5",
1824
- ),
1825
- )
1826
-
1827
- # This is the raw access data saved in erasure format (with placeholders preserved) to perform a masking request.
1828
- # First saved on the access node, and then copied to the corresponding erasure node.
1829
- data_for_erasures = Column( # An encrypted JSON String - saved as a list of rows
1830
- StringEncryptedType(
1831
- type_in=JSONTypeOverride,
1832
- key=CONFIG.security.app_encryption_key,
1833
- engine=AesGcmEngine,
1834
- padding="pkcs5",
1835
- ),
1836
- )
1837
-
1838
- # Written after an erasure is completed
1839
- rows_masked = Column(Integer)
1840
- # Written after a consent request is completed - not all consent
1841
- # connectors will end up sending a request
1842
- consent_sent = Column(Boolean)
1843
-
1844
- # For async tasks awaiting callback
1845
- callback_succeeded = Column(Boolean)
1846
-
1847
- # Stores a serialized collection that can be transformed back into a Collection to help
1848
- # execute the current task
1849
- collection = Column(MutableDict.as_mutable(JSONB))
1850
- # Stores key details from traversal.traverse in the format of TraversalDetails
1851
- traversal_details = Column(MutableDict.as_mutable(JSONB))
1852
-
1853
- privacy_request: RelationshipProperty[PrivacyRequest] = relationship(
1854
- "PrivacyRequest",
1855
- back_populates="request_tasks",
1856
- uselist=False,
1857
- )
1858
-
1859
- @property
1860
- def request_task_address(self) -> CollectionAddress:
1861
- """Convert the collection_address into Collection Address format"""
1862
- return CollectionAddress.from_string(self.collection_address)
1863
-
1864
- @property
1865
- def is_root_task(self) -> bool:
1866
- """Convenience helper for asserting whether the task is a root task"""
1867
- return self.request_task_address == ROOT_COLLECTION_ADDRESS
1868
-
1869
- @property
1870
- def is_terminator_task(self) -> bool:
1871
- """Convenience helper for asserting whether the task is a terminator task"""
1872
- return self.request_task_address == TERMINATOR_ADDRESS
1873
-
1874
- def get_cached_task_id(self) -> Optional[str]:
1875
- """Gets the cached celery task ID for this request task."""
1876
- cache: FidesopsRedis = get_cache()
1877
- task_id = cache.get(get_async_task_tracking_cache_key(self.id))
1878
- return task_id
1879
-
1880
- def get_access_data(self) -> List[Row]:
1881
- """Helper to retrieve access data or default to empty list"""
1882
- return self.access_data or []
1883
-
1884
- def get_data_for_erasures(self) -> List[Row]:
1885
- """Helper to retrieve erasure data needed to build masking requests or default to empty list"""
1886
- return self.data_for_erasures or []
1887
-
1888
- def update_status(self, db: Session, status: ExecutionLogStatus) -> None:
1889
- """Helper method to update a task's status"""
1890
- self.status = status
1891
- self.save(db)
1892
-
1893
- def get_tasks_with_same_action_type(
1894
- self, db: Session, collection_address_str: str
1895
- ) -> Query:
1896
- """Fetch task on the same privacy request and action type as current by collection address"""
1897
- return db.query(RequestTask).filter(
1898
- RequestTask.privacy_request_id == self.privacy_request_id,
1899
- RequestTask.action_type == self.action_type,
1900
- RequestTask.collection_address == collection_address_str,
1901
- )
1902
-
1903
- def get_pending_downstream_tasks(self, db: Session) -> Query:
1904
- """Returns the immediate downstream task objects that are still pending"""
1905
- return db.query(RequestTask).filter(
1906
- RequestTask.privacy_request_id == self.privacy_request_id,
1907
- RequestTask.action_type == self.action_type,
1908
- RequestTask.collection_address.in_(self.downstream_tasks or []),
1909
- RequestTask.status == ExecutionLogStatus.pending,
1910
- )
1911
-
1912
- def can_queue_request_task(self, db: Session, should_log: bool = False) -> bool:
1913
- """Returns True if upstream tasks are complete and the current Request Task
1914
- is not running in another celery task.
1915
-
1916
- This check ignores its database status - that is checked elsewhere.
1917
- """
1918
- return self.upstream_tasks_complete(
1919
- db, should_log
1920
- ) and not self.request_task_running(should_log)
1921
-
1922
- def upstream_tasks_complete(self, db: Session, should_log: bool = False) -> bool:
1923
- """Determines if all of the upstream tasks of the current task are complete"""
1924
- upstream_tasks: Query = self.upstream_tasks_objects(db)
1925
- tasks_complete: bool = all(
1926
- upstream_task.status in COMPLETED_EXECUTION_LOG_STATUSES
1927
- for upstream_task in upstream_tasks
1928
- ) and upstream_tasks.count() == len(self.upstream_tasks or [])
1929
-
1930
- if not tasks_complete and should_log:
1931
- logger.debug(
1932
- "Upstream tasks incomplete for {} task {}.",
1933
- self.action_type.value,
1934
- self.collection_address,
1935
- )
1936
-
1937
- return tasks_complete
1938
-
1939
- def upstream_tasks_objects(self, db: Session) -> Query:
1940
- """Returns Request Task objects that are upstream of the current Request Task"""
1941
- upstream_tasks: Query = db.query(RequestTask).filter(
1942
- RequestTask.privacy_request_id == self.privacy_request_id,
1943
- RequestTask.collection_address.in_(self.upstream_tasks or []),
1944
- RequestTask.action_type == self.action_type,
1945
- )
1946
- return upstream_tasks
1947
-
1948
- def request_task_running(self, should_log: bool = False) -> bool:
1949
- """Returns a rough measure if the Request Task is already running -
1950
- not 100% accurate.
1951
-
1952
- This is further only applicable if you are running workers and
1953
- CONFIG.execution.task_always_eager=False. This is just an extra check to reduce possible
1954
- over-scheduling, but it is also okay if the same node runs multiple times.
1955
- """
1956
- celery_task_id: Optional[str] = self.get_cached_task_id()
1957
- if not celery_task_id:
1958
- return False
1959
-
1960
- if should_log:
1961
- logger.debug(
1962
- "Celery Task ID {} found for {} task {}.",
1963
- celery_task_id,
1964
- self.action_type.value,
1965
- self.collection_address,
1966
- )
1967
-
1968
- task_in_flight: bool = celery_tasks_in_flight([celery_task_id])
1969
-
1970
- if task_in_flight and should_log:
1971
- logger.debug(
1972
- "Celery Task {} already processing for {} task {}.",
1973
- celery_task_id,
1974
- self.action_type.value,
1975
- self.collection_address,
1976
- )
1977
-
1978
- return task_in_flight