Skip to content

NoReverseMatch exception thrown for custom primary keys #72

Closed
@murraylchapman

Description

@murraylchapman

If you attempt to attach DjangoObjectActions to a model that has a primary key that is neither hex nor decimal, a NoReverseMatch exception is thrown.

The problem is this code in _get_action_urls():

            # change, supports pks that are numbers or uuids
            url(r'^(?P<pk>[0-9a-f\-]+)/actions/(?P<tool>\w+)/$',

This seems arbitrary, considering that we're creating a new custom URL space and all primary keys have to be already URL-compatible.

I fixed my use case by relaxing the pattern:

            url(r'^(?P<pk>[\w\\-]+)/actions/(?P<tool>\w+)/$',

...which doesn't appear to have any negative consequences.

Recommendation:

  1. Relax the regex; or

  2. Provide a mechanism to easily override the default assumptions about primary key regex; or

  3. Make it easier to add extra urls to the results of this function. I tried to create a subclass that appended another URL pattern to the results of super(DjangoObjectActions, self)._get_action_urls() but I needed a bunch of context that's created within that method, so it was just easier to copy the entire method into the subclass and change the regex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions