Fix regressions, add future-proofing for URI templates and new APIs.

Review Request #12726 — Created Nov. 16, 2022 and updated

chipx86
Review Board
release-5.0.x
reviewboard

We recently had some conflicts with the new root resources for reviews
and comments, and added collision detection for URI template
registrations.

Since these went in, a couple regressions were discovered:

  1. The root review/comment APIs had registered item APIs, which don't
    actually work, due to the lack of uri_object_key = None.

  2. The root diff comment API had the wrong URL
    (/api/review-diff-comment/ instead of /api/diff-comments/) and
    URI template (review_diff_comment instead of all_diff_comments).

  3. The review request file attachment comments API mistakenly had a
    all_reviews_file_attachment_comments URI template, which doesn't
    represent that resource.

  4. Some of the URI templates were pointing to the wrong API resources,
    based on a comparison to the Review Board 3 API on RBCommons.

Some of these were just wrong resources or attributes being set, which
regressed in 5.0.1. However, most of this is just due to the shaky
foundation that URI templates have historically been on. We didn't have
proper management of any of this, and any kind of testing is brand-new.
So a big part of this change is simply an audit of the URI templates.

To address the problems we've hit, we're now deprecating the older
confusing URI templates that triggered collisions before, and are
instead replacing them with namespaced versions. These are all ones that
pertain to diffs, reviews, review replies, and review requests.

The complete list of URI templates have been added to the RootResource
documentation, as have the legacy names. These are versioned (starting
with 4.0) to help users and us.

All legacy names are now considered deprecated, but will still point to
the old locations pertaining to the Review Board 3 API.

Legacy URI templates are also registered in a way that doesn't create
an entry per API root resource location, which will save memory for
installs using Local Sites.

Unit tests pass.

Diffed the list against the 5.0.1 and 3.0.x releases to verify
that the resulting URI templates seem to be compatible with what we
intended before and what we're wanting to point to now, and that
all legacy URLs correctly match.

Built the docs and checked that the resulting Root Resource's docs
on URI templates correctly linked to each target resource page.

Summary
Fix regressions, add future-proofing for URI templates and new APIs.
Description From Last Updated

I went through the resources that exist in our expected_uri_templates reference and found some that are missing from the RootResource …

maubinmaubin

'typing.Dict' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

I'm thinking maybe file_diff would be a better name? Since it matches the policy_id here and would follow the URI …

maubinmaubin

This key should be extensions instead of extension-list.

maubinmaubin

These were actually added in 5.0.1.

maubinmaubin

I think it could be worthwhile to add comments here to show which URI templates and names are legacy/deprecated. Or …

maubinmaubin
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
Review request changed

Change Summary:

Removed an unused import.

Description:

   

We recently had some conflicts with the new root resources for reviews

    and comments, and added collision detection for URI template
    registrations.

   
   

Since these went in, a couple regressions were discovered:

   
   
  1. The root review/comment APIs had registered item APIs, which don't
    actually work, due to the lack of uri_object_key = None.

   
  1. The root diff comment API had the wrong URL
    (/api/review-diff-comment/ instead of /api/diff-comments/) and
    URI template (review_diff_comment instead of all_diff_comments).

   
  1. The review request file attachment comments API mistakenly had a
    all_reviews_file_attachment_comments URI template, which doesn't
    represent that resource.

   
  1. Some of the URI templates were pointing to the wrong API resources,
    based on a comparison to the Review Board 3 API on RBCommons.

   
   

Some of these were just wrong resources or attributes being set, which

    regressed in 5.0.1. However, most of this is just due to the shaky
    foundation that URI templates have historically been on. We didn't have
    proper management of any of this, and any kind of testing is brand-new.
    So a big part of this change is simply an audit of the URI templates.

   
   

To address the problems we've hit, we're now deprecating the older

    confusing URI templates that triggered collisions before, and are
    instead replacing them with namespaced versions. These are all ones that
    pertain to diffs, reviews, review replies, and review requests.

   
   

The complete list of URI templates have been added to the RootResource

    documentation, as have the legacy names. These are versioned (starting
    with 4.0) to help users and us.

   
   

All legacy names are now considered deprecated, but will still point to

    the old locations pertaining to the Review Board 3 API.

  +
  +

Legacy URI templates are also registered in a way that doesn't create

  + an entry per API root resource location, which will save memory for
  + installs using Local Sites.

Commits:

Summary
-
Fix regressions, add future-proofing for URI templates and new APIs.
+
Fix regressions, add future-proofing for URI templates and new APIs.

Diff:

Revision 2 (+1558 -120)

Show changes

Checks run (2 succeeded)

flake8 passed.
JSHint passed.
maubin
  1. Good stuff, thanks for doing this! Really helps to clear things up with the URI templates while keeping legacy behaviour. And good catch for the root reviews/comments fixes.

    1. Thanks for the review! Yeah I figured we might as well do this now, and give ourselves a better foundation for later when we rethink all this.

      I have some thoughts on a future successor to uri_templates when we finally do a new API revision, based on what we've encountered this release.

  2. I went through the resources that exist in our expected_uri_templates reference and found some that are missing from the RootResource documentation:
    Resource | URI template name
    ---------|-------------------
    File Diff Comment List | file_diff_comments
    Diff Context | diff_context
    File Attachment | file_attachment
    File Attachment List | file_attachments

    1. Ah, good catches! Thanks!

  3. I'm thinking maybe file_diff would be a better name? Since it matches the policy_id here and would follow the URI naming for the FileDiffCommentResource (which I set to file_diff_comment in 5.0.1). Or you could change the FileDiffCommentResource URI name to diff_file_comment.

    1. Yeah, this one's tricky.

      We can't change the URI name or we break API compatibility. Same with the policy ID.

      I was aiming to keep all diff-related resources under the same prefix, but it's probably better to keep consistent with the rest of the naming.

      I'll make this change, and I think I'll move the original_file/patched_file under this name as well.

    2. That sounds good to me.

  4. reviewboard/webapi/resources/root.py (Diff revision 2)
     
     

    This key should be extensions instead of extension-list.

  5. reviewboard/webapi/resources/root.py (Diff revision 2)
     
     
     
     
     
     
     
     

    These were actually added in 5.0.1.

  6. reviewboard/webapi/tests/test_root.py (Diff revision 2)
     
     

    I think it could be worthwhile to add comments here to show which URI templates and names are legacy/deprecated. Or move them so that they have their own section in the dict, like how you did it in the RootResource documentation. But then again we could always just refer to the documentation for this info.

    1. Good idea! I'll go ahead and do this.

  7. 
      
Loading...