Skip to content

Commit

Permalink
Fix metadata formatting workarounds on the server
Browse files Browse the repository at this point in the history
As described in e-mission/cordova-usercache#17, it
looks like we never actually passed in a timezone from the client, which means
that the code to check for timezone validity was never tested.

And of course, that which is not tested is broken. Fix the check by adding
appropriate imports and module names.

With this change, we now store the incoming config

```
2016-07-25 15:28:17,503:DEBUG:module_name = emission.net.usercache.formatters.ios.consent
2016-07-25 15:28:17,555:DEBUG:write_ts = 1469477974
2016-07-25 15:28:17,556:DEBUG:insert called
2016-07-25 15:28:17,556:DEBUG:entry was fine, no need to fix it
2016-07-25 15:28:17,557:DEBUG:Inserting entry AttrDict({u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), u'_id': ObjectId('57969202115514afcd79338b'), u'data': AttrDict({u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'}), u'metadata': AttrDict({u'platform': u'ios', 'write_local_dt': LocalDate({'hour': 13, 'month': 7, 'second': 34, 'weekday': 0, 'year': 2016, 'timezone': u'America/Los_Angeles', 'day': 25, 'minute': 19}), u'read_ts': 0, u'key': u'config/consent', u'plugin': u'none', u'write_ts': 1469477974, u'type': u'rw-document', u'time_zone': u'America/Los_Angeles', 'write_fmt_time': '2016-07-25T13:19:34-07:00'})}) into timeseries
```

and return it as a document.

```
2016-07-25 15:28:45,014:DEBUG:finished querying values for ['config/consent']
2016-07-25 15:28:45,014:DEBUG:finished querying values for []
2016-07-25 15:28:45,015:DEBUG:Found 2 user overrides for user 0763de67-f61e-3f5d-90e7-518e69793954
2016-07-25 15:28:45,015:DEBUG:last entry is Entry({u'user_id': UUID('0763de67-f61e-3f5d-90e7-518e69793954'), u'_id': ObjectId('57969202115514afcd79338b'), u'data': {u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'}, u'metadata': {u'write_fmt_time': u'2016-07-25T13:19:34-07:00', u'write_ts': 1469477974, u'plugin': u'none', u'time_zone': u'America/Los_Angeles', u'platform': u'ios', u'write_local_dt': {u'hour': 13, u'month': 7, u'second': 34, u'weekday': 0, u'year': 2016, u'timezone': u'America/Los_Angeles', u'day': 25, u'minute': 19}, u'key': u'config/consent', u'read_ts': 0, u'type': u'rw-document'}})
2016-07-25 15:28:45,015:DEBUG:for 0763de67-f61e-3f5d-90e7-518e69793954, config is Consentconfig({u'category': u'emSensorDataCollectionProtocol', u'approval_date': u'2016-07-14', u'protocol_id': u'2014-04-6267'})
2016-07-25 15:28:45,016:DEBUG:Result = {'updatedExisting': False, u'nModified': 0, u'ok': 1, u'upserted': ObjectId('5796929d115514afcd793398'), u'n': 1} after updating document config/consent
```
  • Loading branch information
shankari committed Jul 25, 2016
1 parent 828d248 commit a31ba77
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion emission/net/usercache/formatters/android/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down
2 changes: 1 addition & 1 deletion emission/net/usercache/formatters/android/sensor_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down
2 changes: 1 addition & 1 deletion emission/net/usercache/formatters/android/sync_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down
6 changes: 4 additions & 2 deletions emission/net/usercache/formatters/ios/consent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import copy
import pytz

import emission.core.wrapper.syncconfig as ecws
import emission.core.wrapper.consentconfig as ecws
import emission.net.usercache.formatters.common as fc

# Currently, we just reflect this back to the user, so not much editing to do
Expand All @@ -12,7 +14,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down
2 changes: 1 addition & 1 deletion emission/net/usercache/formatters/ios/sensor_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down
4 changes: 3 additions & 1 deletion emission/net/usercache/formatters/ios/sync_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import copy
import pytz

import emission.core.wrapper.syncconfig as ecws
import emission.net.usercache.formatters.common as fc
Expand All @@ -12,7 +14,7 @@ def format(entry):
metadata = entry.metadata
try:
valid_tz = pytz.timezone(entry.metadata.time_zone)
except UnknownTimeZoneError, e:
except pytz.UnknownTimeZoneError, e:
logging.warn("Got error %s while checking format validity" % e)
# Default timezone in for the Bay Area, which is probably a fairly safe
# assumption for now
Expand Down

0 comments on commit a31ba77

Please sign in to comment.