Browse Source

fix: Renormalize snuba events (#13329)

SnubaEvents are not renormalize because they use NodeData directly. This patch adds the wrapper class to NodeData to do just that.
Jan Michael Auer 5 years ago
parent
commit
54764bf9d9
2 changed files with 8 additions and 8 deletions
  1. 7 7
      src/sentry/db/models/fields/node.py
  2. 1 1
      src/sentry/models/event.py

+ 7 - 7
src/sentry/db/models/fields/node.py

@@ -46,7 +46,7 @@ class NodeData(collections.MutableMapping):
         data={...} means, this is an object that should be saved to nodestore.
     """
 
-    def __init__(self, field, id, data=None):
+    def __init__(self, field, id, data=None, wrapper=None):
         self.field = field
         self.id = id
         self.ref = None
@@ -54,6 +54,9 @@ class NodeData(collections.MutableMapping):
         # (this does not mean the Event is mutable, it just removes ref checking
         #  in the case of something changing on the data model)
         self.ref_version = None
+        self.wrapper = wrapper
+        if data is not None and self.wrapper is not None:
+            data = self.wrapper(data)
         self._node_data = data
 
     def __getstate__(self):
@@ -130,8 +133,8 @@ class NodeData(collections.MutableMapping):
             raise NodeIntegrityFailure(
                 'Node reference for %s is invalid: %s != %s' % (self.id, ref, self.ref, )
             )
-        if self.field is not None and self.field.wrapper is not None:
-            data = self.field.wrapper(data)
+        if self.wrapper is not None:
+            data = self.wrapper(data)
         self._node_data = data
 
     def bind_ref(self, instance):
@@ -216,10 +219,7 @@ class NodeField(GzippedDictField):
             # to load data from, and no data to save.
             value = None
 
-        if value is not None and self.wrapper is not None:
-            value = self.wrapper(value)
-
-        return NodeData(self, node_id, value)
+        return NodeData(self, node_id, value, wrapper=self.wrapper)
 
     def get_prep_value(self, value):
         """

+ 1 - 1
src/sentry/models/event.py

@@ -512,7 +512,7 @@ class SnubaEvent(EventCommon):
         node_id = SnubaEvent.generate_node_id(
             self.snuba_data['project_id'],
             self.snuba_data['event_id'])
-        self.data = NodeData(None, node_id, data=None)
+        self.data = NodeData(None, node_id, data=None, wrapper=EventDict)
 
     def __getattr__(self, name):
         """