Ottomata has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393613 )

Change subject: Pop capsule up to top level before applying format caster 
functions
......................................................................

Pop capsule up to top level before applying format caster functions

If a an event producer sets capsule level fields AND those
capsule level fields have format specifiers that are used
to parse that field out of the raw event data separate from
the incoming event data, the incoming event data will overwrite
whatever was parsed from the raw non-event data and casted
into that field.

This caused a bug with the Popups schema and userAgent fields.
The Popups EventLogging extension code would set userAgent
sometimes:
https://github.com/wikimedia/mediawiki-extensions-EventLogging/blob/28f871d38c0f32e7b641fa9364e58f4b7666633e/includes/EventLogging.php#L71

With the code before this patch, this means that the raw userAgent would be 
used, rather than the parsed one.

After this patch, the event's userAgent will be parsed by the parse_ua caster 
function.

Bug: T178440
Change-Id: I37ca9e9bfce7c1c8dae8d8788b8f5c9d20b8a309
---
M eventlogging/parse.py
1 file changed, 12 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/eventlogging 
refs/changes/13/393613/1

diff --git a/eventlogging/parse.py b/eventlogging/parse.py
index b40c293..7a3720e 100644
--- a/eventlogging/parse.py
+++ b/eventlogging/parse.py
@@ -184,8 +184,19 @@
         # Filter out the caster-key pairs where caster is None
         caster_key_pairs = [pair for pair in zip(self.casters, keys)
                             if pair[0]]
-        event = {k: f(match.group(k)) for f, k in caster_key_pairs}
+
+        # First bring the submitted data up to the top level.  Before
+        # this step, the event dict looks something like:
+        # { "capsule": { "event": { "myfield": "data", ... } }, "userAgent": 
"...", "dt": "...", ... }
+        # And after it will look like:
+        # { "event": { "myfield": "data", ... }, "userAgent": "...", "dt": 
"...", ... }
         event.update(event.pop('capsule'))
+
+        # For any format specifiers with 'caster' functions, apply those 
functions
+        # to the matched fields.  E.g. event['userAgent'] = parse_ua(userAgent)
+        event = {k: f(match.group(k)) for f, k in caster_key_pairs}
+
+        # Add a uuid for this event.
         event['uuid'] = capsule_uuid(event)
 
         return Event(event)

-- 
To view, visit https://gerrit.wikimedia.org/r/393613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37ca9e9bfce7c1c8dae8d8788b8f5c9d20b8a309
Gerrit-PatchSet: 1
Gerrit-Project: eventlogging
Gerrit-Branch: master
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to