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

Replace storage.update_annotation with an AnnotationWriteService method #7967

Merged
merged 8 commits into from
Jun 15, 2023

Conversation

jon-betts
Copy link
Contributor

@jon-betts jon-betts commented May 3, 2023

For:

Requires:

Testing notes

  • Start h, the client, Via and ViaHTML

Update annotation

Migrate annotation URL

{
    "http://example.com": {
        "url": "http://example.net",
        "document": {"title": "Example Domain"}
    }
}

@jon-betts jon-betts self-assigned this May 3, 2023
@jon-betts jon-betts force-pushed the anno-write-svc-create branch 2 times, most recently from f06bb09 to aa848a2 Compare May 4, 2023 16:52
Base automatically changed from anno-write-svc-create to main May 4, 2023 17:06
@jon-betts jon-betts force-pushed the anno-write-svc-update branch 3 times, most recently from ae2d4fd to 8d3b6d1 Compare May 24, 2023 17:23
@jon-betts jon-betts removed the WIP label May 24, 2023
data: dict,
update_timestamp: bool = True,
reindex_tag: str = "storage.update_annotation",
enforce_write_permission: bool = True,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to move the migration stuff to this service, at which point a lot of these args would become private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default of enforce_write_permission here is a change in behavior. Previously we never did this. Now we do it when updating on behalf of the user.

# the target URI must match one of a group's defined scopes
and not url_in_scope(
annotation.target_uri, [scope.scope for scope in group.scopes]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small un-related refactor to point out these are two parts of the same condition.

def celery(self, patch, pyramid_request):
celery = patch("h.tasks.url_migration.celery")
celery.request = pyramid_request
return celery
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was having some untraceable coverage issues, and this seemed related, and a good thing to fix.

@@ -34,6 +34,7 @@ def test_it_captures_initial_errors(self):
def failing_method():
raise ValueError("Oh no!")

# pragma: nocover
yield 1 # pylint: disable=unreachable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Random coverage fix

@jon-betts jon-betts requested a review from marcospri May 31, 2023 12:45
Copy link
Member

@marcospri marcospri left a comment

Choose a reason for hiding this comment

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

Noting of value to add here. Changes make sense and the code is in much better shape now.

Tried the testing instruction and discovered that URL migration interface in the process.

@@ -5,97 +5,15 @@
for storing and retrieving annotations. Data passed to these functions is
assumed to be validated.
"""
# FIXME: This module was originally written to be a single point of
# indirection through which the storage backend could be swapped out on
Copy link
Member

Choose a reason for hiding this comment

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

originally written to be a single point of indirection

Oh well, that didn't happen

# Don't update "edited" timestamp on annotation cards.
update_timestamp=False,
reindex_tag="URLMigrationService.move_annotations",
# This action is taken by the admin user most of the time, who
Copy link
Member

Choose a reason for hiding this comment

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

Most of the time?

# pylint: disable=too-many-arguments
self,
annotation: Annotation,
data: dict,
Copy link
Member

Choose a reason for hiding this comment

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

Not in the scope of this PR but these APIs where we just have some "data" in with no shape or form are difficult to change.

Some changes work because everything is very abstract but other times is tricky to spot a problem because it will silently fail or just do nothing.

Anyway, just rambling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's confusing as the data is a very specific shape, but what shape is that?

Jon Betts added 8 commits June 15, 2023 19:04
@jon-betts jon-betts merged commit 13a37dc into main Jun 15, 2023
@jon-betts jon-betts deleted the anno-write-svc-update branch June 15, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants