Skip to content

Preserve values of repeated nested elements in entries - #618

Open
bfs2021 wants to merge 1 commit into
kurtmckee:mainfrom
bfs2021:fix/repeated-nested-element-loss
Open

bfs2021 wants to merge 1 commit into
kurtmckee:mainfrom
bfs2021:fix/repeated-nested-element-loss

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 21, 2026

Copy link
Copy Markdown

Problem

When an entry contains the same namespaced element repeated under different parent elements, the values clobber each other and all but the last one are dropped, because entries are built as flat dictionaries keyed by element name.

Example feed (from the issue):

<bc:location>
  <bc:name>Location name</bc:name>
</bc:location>
<bc:contact>
  <bc:name>Contact name</bc:name>
</bc:contact>

Parsing this currently yields bc_name == 'Contact name'; 'Location name' is silently lost.

Root cause

In XMLParserMixin.pop(), an entry-level element value is stored with a same-depth last-wins overwrite (self.depth <= old_value_depth via property_depth_map). Two occurrences of <bc:name> nested under different parents (bc:location vs bc:contact) reach that path at the same depth, so the second store overwrites the first even though the values come from unrelated parent elements.

Fix

Track the parent element chain alongside the depth in property_depth_map (via a new _store_or_merge() helper used by both the entry-level and feed-level store paths in pop()):

  • same depth and same parent chain: keep the existing last-wins overwrite, so deliberate fallback semantics (e.g. media:title falling back to title, repeated dc:creator mapping onto author) are unchanged;
  • same depth but a different parent chain (the issue's case): collect the values into a list instead of dropping the earlier one.

Testing

Added tests/wellformed/namespace/rss2.0repeatednestedelements.xml with the feed from the issue, expecting entries[0]['bc_name'] == ['Location name', 'Contact name']. Before the fix it fails on both the strict and loose parser; after the fix it passes, and the full test suite shows no new failures (only the 6 pre-existing failures unrelated to this change remain).

Fixes #139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elements get dropped from feed items with repeated nested elements

1 participant