WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8288ba5

Browse files
authored
Merge pull request #794 from lindsay-stevens/pyxform-791
791: fix support for a source referencing an ancestor repeat target
2 parents fa24bf3 + 5b0289a commit 8288ba5

File tree

3 files changed

+349
-21
lines changed

3 files changed

+349
-21
lines changed

pyxform/survey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def is_repeat(e: SurveyElement) -> bool:
113113
if reference_parent:
114114
# The LCAR may or may not be the closest ancestor repeat for source or target,
115115
# but there's always at least the LCAR, so a check for None isn't needed.
116-
source_car, _ = next(source.iter_ancestors(condition=is_repeat), None)
117-
target_car, _ = next(target.iter_ancestors(condition=is_repeat), None)
116+
source_car, _ = next(source.iter_ancestors(condition=is_repeat), (None, None))
117+
target_car, _ = next(target.iter_ancestors(condition=is_repeat), (None, None))
118118
# May return None if LCAR is a child of the Survey, or only non-repeating group(s).
119119
lcar_not_in_repeat = next(lcar.iter_ancestors(condition=is_repeat), None) is None
120120

pyxform/survey_element.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def __setattr__(self, key, value):
9494
self._survey_element_xpath = None
9595
super().__setattr__(key, value)
9696

97+
def __repr__(self):
98+
return f"""{super().__repr__()}(name="{self.name}")"""
99+
97100
def __init__(
98101
self,
99102
name: str,
@@ -195,13 +198,6 @@ def lowest_common_ancestor(
195198
"""
196199
Get the relation type, steps from self, steps from other, and the common ancestor.
197200
"""
198-
199-
# Quick check for immediate relation.
200-
if self.parent is other:
201-
return "Parent (other)", 1, 0, other
202-
elif other.parent is self:
203-
return "Parent (self)", 0, 1, self
204-
205201
# Filtering
206202
if group_type:
207203
type_filter = {group_type}
@@ -211,10 +207,10 @@ def lowest_common_ancestor(
211207
# Traversal tracking
212208
self_ancestors = {}
213209
other_ancestors = {}
214-
self_current = self
215-
other_current = other
216-
self_distance = 0
217-
other_distance = 0
210+
self_current = self.parent
211+
other_current = other.parent
212+
self_distance = 1
213+
other_distance = 1
218214
lca = None
219215

220216
# Traverse up both ancestor chains as far as necessary.

0 commit comments

Comments
 (0)