You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has anyone encountered issues with the LogViewSet in handling JSON data and parsing timestamps with AM/PM format? I've encountered the following issues and would like to gather more insights or solutions if available.
The LogViewSet attempts to handle incoming JSON data, but i encounter some issues with both accessing request.body and parsing timestamps that include AM/PM format.
Testing Scenario: Testing of the LogViewSet endpoint.
"What changed?" Response from Apple
Attempted to force a pass update without actually making changes to the pass instance (This was executed using pass_instance.push_notification() on a pass instance with no modified data.) triggering Apple to POST to the log endpoint. The message was "What changed? ........" since the pass had no modifications since the last updated_at.
Accessing request.body:
The LogViewSet's create method uses json.loads(request.body) to parse incoming JSON data. However, this lead me to a RawPostDataException because request.body can only be read once in Django's request lifecycle.
Note: I've noticed a difference in how request.body is handled between different views within the library. For instance, the RegisterPassViewSet successfully uses request.body to parse JSON data without issues. However, in the LogViewSet, direct access to request.body leads to a RawPostDataException. Am i the only one experiencing this error?
Parsing Timestamps with AM/PM Format:
Another issue arises in Log.parse_log(log, message), specifically with parsing timestamps provided by Apple servers that include AM/PM format (%p). The current implementation of datetime.datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S %z") does not account for %p, leading to parsing errors when timestamps contain AM/PM indicators.
Proposed Solutions:
Handling request.body:
Refactor LogViewSet.create to utilize DRF's request parsing mechanisms (request.data) instead of directly accessing request.body. This approach ensures compatibility with Django's request handling and avoids RawPostDataException.
Modify the timestamp parsing logic in Log.parse_log to include %p in the format string ("%Y-%m-%d %H:%M:%S %p %z") when using datetime.datetime.strptime. This adjustment ensures correct parsing of timestamps that include AM/PM indicators.
classLog(models.Model):
# model fields@classmethoddefparse_log(cls, log, message):
# method codelog.created_at=datetime.datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S %p %z") # Include %p to parse AM/PM
Here's a screenshot showing the request from Apple with the data in request.data and the message containing the AM/PM formatted datetime.
The text was updated successfully, but these errors were encountered:
Hello again!
Has anyone encountered issues with the
LogViewSet
in handling JSON data and parsing timestamps with AM/PM format? I've encountered the following issues and would like to gather more insights or solutions if available.The
LogViewSet
attempts to handle incoming JSON data, but i encounter some issues with both accessingrequest.body
and parsing timestamps that include AM/PM format.Testing Scenario: Testing of the
LogViewSet
endpoint.pass_instance.push_notification()
on a pass instance with no modified data.) triggering Apple to POST to the log endpoint. The message was "What changed? ........" since the pass had no modifications since the lastupdated_at
.Accessing
request.body
:The
LogViewSet
'screate
method usesjson.loads(request.body)
to parse incoming JSON data. However, this lead me to aRawPostDataException
becauserequest.body
can only be read once in Django's request lifecycle.Parsing Timestamps with AM/PM Format:
Another issue arises in
Log.parse_log(log, message)
, specifically with parsing timestamps provided by Apple servers that include AM/PM format (%p
). The current implementation ofdatetime.datetime.strptime(timestamp_str, "%Y-%m-%d %H:%M:%S %z")
does not account for%p
, leading to parsing errors when timestamps contain AM/PM indicators.Proposed Solutions:
Handling
request.body
:Refactor
LogViewSet.create
to utilize DRF's request parsing mechanisms (request.data
) instead of directly accessingrequest.body
. This approach ensures compatibility with Django's request handling and avoidsRawPostDataException
.Parsing Timestamps:
Modify the timestamp parsing logic in
Log.parse_log
to include%p
in the format string ("%Y-%m-%d %H:%M:%S %p %z"
) when usingdatetime.datetime.strptime
. This adjustment ensures correct parsing of timestamps that include AM/PM indicators.Here's a screenshot showing the request from Apple with the data in
request.data
and the message containing the AM/PM formatted datetime.The text was updated successfully, but these errors were encountered: