Skip to content

Commit

Permalink
Handle unknown properties in report XML gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
jgosmann committed Jul 25, 2023
1 parent 35f72f4 commit 7fadca0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

[0.9.3] - unreleased
--------------------

Fixed
^^^^^

* Gracefully handle unknown properties within report XML. In particular, this
should allow to process reports send by Google again, which was not working
anymore starting June 2023.


[0.9.2] - 2023-06-30
--------------------

Expand Down
5 changes: 4 additions & 1 deletion dmarc_metrics_exporter/deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from zipfile import ZipFile

from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.parsers.config import ParserConfig
from xsdata.formats.dataclass.parsers.xml import XmlParser

from dmarc_metrics_exporter.dmarc_event import (
Expand Down Expand Up @@ -49,7 +50,9 @@ def handle_text_xml(content: str) -> Generator[str, None, None]:
def get_aggregate_report_from_email(
msg: EmailMessage,
) -> Generator[Feedback, None, None]:
parser = XmlParser(context=XmlContext())
parser = XmlParser(
context=XmlContext(), config=ParserConfig(fail_on_unknown_properties=False)
)
has_found_a_report = False
for part in msg.walk():
if part.get_content_type() in content_type_handlers:
Expand Down
1 change: 1 addition & 0 deletions dmarc_metrics_exporter/model/tests/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create_sample_xml(*, report_id: str = "12598866915817748661") -> str:
<p>none</p>
<sp>none</sp>
<pct>100</pct>
<np>none</np>
</policy_published>
<record>
<row>
Expand Down
5 changes: 4 additions & 1 deletion dmarc_metrics_exporter/model/tests/test_deserialization.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.parsers.config import ParserConfig

from dmarc_metrics_exporter.model.dmarc_aggregate_report import Feedback

from .sample_data import SAMPLE_DATACLASS, create_sample_xml


def test_deserialization():
parser = XmlParser(context=XmlContext())
parser = XmlParser(
context=XmlContext(), config=ParserConfig(fail_on_unknown_properties=False)
)
assert parser.from_string(create_sample_xml(), Feedback) == SAMPLE_DATACLASS

0 comments on commit 7fadca0

Please sign in to comment.