Skip to content

Commit 0e54225

Browse files
committed
Fix grouping of safelisted annotations
Annotation grouping was based on the filename and line number. Unfortunately, this fails when the annotation comes from the safelist, where the filename is the safelist, and the line number is 0. This was causing issues in pii annotation parsing on edx-platform. To address this, we group annotations by line number and extra[model_id] fields.
1 parent 1d8e4fe commit 0e54225

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ Change Log
1111

1212
.. There should always be an "Unreleased" section for changes pending release.
1313
14-
[1.0.0] - 2021-01-25
14+
[1.0.1] - 2021-01-22
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
* Fix grouping of safelisted annotations
18+
19+
[1.0.0] - 2021-01-21
1520
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1621

1722
* BREAKING CHANGE: Improvement of some error messages

code_annotations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Extensible tools for parsing annotations in codebases.
33
"""
44

5-
__version__ = '1.0.0'
5+
__version__ = '1.0.1'

code_annotations/base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,23 +447,28 @@ def iter_groups(self, annotations):
447447
"""
448448
Iterate on groups of annotations.
449449
450-
Annotations are considered as a group when they all have the same `line_number`, which should point to the
451-
beginning of the annotation group.
450+
Annotations are considered as a group when they all have the same `line_number` and optional
451+
`extra['object_id']`. The line number points to the beginning of the annotation group. The `object_id` is set
452+
mostly for annotations parsed from a safelist.
452453
453454
Yield:
454455
annotations (annotation list)
455456
"""
456457
current_group = []
457458
current_line_number = None
459+
current_object_id = None
458460
for annotation in annotations:
459461
line_number = annotation["line_number"]
462+
object_id = annotation.get("extra", {}).get("object_id")
460463
line_number_changed = line_number != current_line_number
461-
if line_number_changed:
464+
object_id_changed = object_id != current_object_id
465+
if line_number_changed or object_id_changed:
462466
if current_group:
463467
yield current_group
464468
current_group.clear()
465469
current_group.append(annotation)
466470
current_line_number = line_number
471+
current_object_id = object_id
467472

468473
if current_group:
469474
yield current_group

0 commit comments

Comments
 (0)