Enforce that API resources have unique URI template names.

Review Request #12682 — Created Oct. 14, 2022 and submitted — Latest diff uploaded

Information

Djblets
release-3.x

Reviewers

We discovered a problem where resources that have the same name will have
their URI templates in the Root resource's URI templates list overwritten by
one another. Depending on the order that the resources are added to the URI
templates list, this can break the API by replacing the URI template for a
resource with another URI template that may not behave in the same way or
support the same methods as the previous one.

This is a problem that requires more thought and a rethink of how we handle
our resources in general, but for now this change applies a solution that
ensures we keep as much compatibility with our previous API behavior as
possible.

This change introduces the uri_template_name and uri_template_name_plural
attributes for use as the names of resources in the URI templates list, instead
of using the name attribute. This defaults to the name, but can be set to
something else to ensure that resource names in the templates list are unique.
This can also be set to None to have the resource omitted from the URI
templates list. When building the URI templates list, we assert that the
names used in it are unique, as to avoid issues where a resource's URI
template is being overwritten by another resource. The
RootResource.register_uri_template method does not check whether the
resource already exists in the templates because there are use cases where
we need to overwrite the URI template of an existing resource.

  • Ran all unit tests.
  • Manually tested Review Board's API Root resource, saw that the URI
    templates list appeared properly.

Commits

Files