Skip to content

Commit

Permalink
Fix grouping of safelisted annotations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
regisb committed Jan 22, 2021
1 parent 1d8e4fe commit 0e54225
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -11,7 +11,12 @@ Change Log

.. There should always be an "Unreleased" section for changes pending release.
[1.0.0] - 2021-01-25
[1.0.1] - 2021-01-22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Fix grouping of safelisted annotations

[1.0.0] - 2021-01-21
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* BREAKING CHANGE: Improvement of some error messages
Expand Down
2 changes: 1 addition & 1 deletion code_annotations/__init__.py
Expand Up @@ -2,4 +2,4 @@
Extensible tools for parsing annotations in codebases.
"""

__version__ = '1.0.0'
__version__ = '1.0.1'
11 changes: 8 additions & 3 deletions code_annotations/base.py
Expand Up @@ -447,23 +447,28 @@ def iter_groups(self, annotations):
"""
Iterate on groups of annotations.
Annotations are considered as a group when they all have the same `line_number`, which should point to the
beginning of the annotation group.
Annotations are considered as a group when they all have the same `line_number` and optional
`extra['object_id']`. The line number points to the beginning of the annotation group. The `object_id` is set
mostly for annotations parsed from a safelist.
Yield:
annotations (annotation list)
"""
current_group = []
current_line_number = None
current_object_id = None
for annotation in annotations:
line_number = annotation["line_number"]
object_id = annotation.get("extra", {}).get("object_id")
line_number_changed = line_number != current_line_number
if line_number_changed:
object_id_changed = object_id != current_object_id
if line_number_changed or object_id_changed:
if current_group:
yield current_group
current_group.clear()
current_group.append(annotation)
current_line_number = line_number
current_object_id = object_id

if current_group:
yield current_group
Expand Down

0 comments on commit 0e54225

Please sign in to comment.