Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: remove unused regex and consolidate curator tag logic #3200

Merged
merged 6 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/config/curation-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ paths:
additionalProperties: false
properties:
curator_tag:
type: string
description: curator-provided tag
$ref: "#/components/schemas/curator_tag"
example:
curator_tag: "new/curator_tag"
responses:
Expand Down Expand Up @@ -376,7 +375,7 @@ paths:
additionalProperties: false
properties:
curator_tag:
type: string
$ref: "#/components/schemas/curator_tag"
id:
$ref: "#/components/schemas/dataset_id"
link:
Expand Down Expand Up @@ -518,6 +517,7 @@ components:
type: array
curator_tag:
"$ref": "#/components/schemas/curator_tag"
nullable: true
dataset_id:
"$ref": "#/components/schemas/dataset_id"
type: object
Expand Down
20 changes: 10 additions & 10 deletions backend/corpora/common/utils/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
ID_REGEX = r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
DATASET_ID_REGEX = f"(?P<dataset_id>{ID_REGEX})"
COLLECTION_ID_REGEX = f"(?P<collection_id>{ID_REGEX})"
CURATOR_TAG_PREFIX_REGEX = r"(?P<tag_prefix>.*)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

CONTROL_CHARS = r"[\x00-\x1f\x7f-\xa0]"
CURATOR_TAG_REGEX = r"(?P<tag>.*)"
CURATOR_TAG_REGEX = r"(?P<tag>.+)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no empty tags



def validate_curator_tag(curator_tag: str) -> bool:
"""
Verify the correct curator tag format is obeyed.
Verify the correct curator tag format is obeyed (i.e., it is not a UUID)

:param curator_tag: the tag name to validate.
:return: True if CURATOR_TAG_PREFIX_REGEX is matched.
:return: True if CURATOR_TAG_REGEX is matched.
"""
regex = f"^({DATASET_ID_REGEX}|{CURATOR_TAG_REGEX})$"
matched = re.match(regex, curator_tag)
if matched and (tag := matched.groupdict().get("tag")):
if not re.search(ID_REGEX, tag):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this because we are only in the business of making sure that we know when to treat an identifier as a uuid, and that is when the identifier takes the precise form of a uuid. Otherwise, if it is not exactly the form of a uuid, we treat it as a curator tag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requirement was explicitly in the ticket when I implemented it. I updated the ticket to reflect the actual requirements.

return
else:
raise ValueError("Curator tag cannot contain the same shape as a UUID.")
raise ValueError("Invalid curator tag.")
if matched:
matches = matched.groupdict()
if matches.get("tag"):
return True
elif matches.get("dataset_id"):
raise ValueError("Curator tag cannot assume UUID format.")
raise ValueError("Curator tag cannot be empty.")
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _test(_tag, _dataset):
self.assertIsNone(_dataset.curator_tag)

dataset = self.generate_dataset(self.session, collection=collection)
tests = [dataset.id, "prefix" + dataset.id, dataset.id + "suffix", "prefix" + dataset.id + "suffix"]
tests = [dataset.id, ""]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(following on from comments above) "prefix" + dataset.id is therefore a valid tag

for tag_name in tests:
with self.subTest(tag_name):
_test(tag_name, dataset)
Expand Down