django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Add SimplePathRouter

Open sevdog opened this issue 5 years ago • 32 comments

Description

Add SimplePathRouter to handle Django 2.x path converters (refs #6148).

sevdog avatar Jul 06 '19 15:07 sevdog

Milestoning for review. Thanks!

tomchristie avatar Jul 08 '19 12:07 tomchristie

It may be improved a bit if support for Django 1.x gets dropped (ie: some bad if will be removed).

sevdog avatar Jul 08 '19 16:07 sevdog

I'm thinking this should be pushed to the 3.11 release, as that is when we'll likely drop Django 1.11

rpkilby avatar Jul 08 '19 17:07 rpkilby

@rpkilby Good call

tomchristie avatar Jul 09 '19 10:07 tomchristie

@rpkilby I have updated with CRUD tests and removed Django 1.11 compact. Tell me if everything is fine for you.

sevdog avatar Jul 13 '19 13:07 sevdog

can you skip tests for Django 1.11 for this PR? dj1.11 seems to be supported for some more time.

I have also added an assertion in SimplePathRouter.get_urls to raise an assertion error if path is not defined.

sevdog avatar Nov 21 '19 20:11 sevdog

Ok... seems that pytest.mark.skipif has not worked as expected. I will recheck it as soon as I can.

sevdog avatar Nov 22 '19 11:11 sevdog

Rebased.

sevdog avatar Dec 05 '19 20:12 sevdog

We've not dropped 1.11 on this pass, since its LTS.

Wondering if we might just outright switch the behavior on the next release - I'd rather we didn't have two different have two different class implementations here.

tomchristie avatar Dec 12 '19 13:12 tomchristie

@tomchristie you are right that a single-class implementation would be better.

I think that it can be done since the difference between those two are just two methods (get_urls and get_get_lookup_*). Those methods could be guided with some initialization param in class constructor.

I will try to refactor the code to have a single class.

sevdog avatar Dec 12 '19 13:12 sevdog

When we drop 1.11 I'd actually probably be okay with us just completely switching to .path, so long as there's some kind of way for users to stick with the older behavior.

There's not really any great options for us here.

tomchristie avatar Dec 12 '19 14:12 tomchristie

@tomchristie could you please check if the latest implementation is fine for you?

sevdog avatar Dec 12 '19 19:12 sevdog

you can now drop the django 1.11

auvipy avatar Apr 04 '20 05:04 auvipy

Code updated, tell me if other changes are needed.

sevdog avatar Apr 11 '20 18:04 sevdog

can you fix the lint error?

auvipy avatar May 11 '20 09:05 auvipy

I've tested this patch on 3.12.2 (after a cherry-pick) in my project and it certainly does what it says on the tin.

Tox on a sedded version of the tests (s, re_path(r'^, path(',g) has no complaints (if we disregard a failure in an AuthToken test on django_master), so I think I'm gonna vendor this while waiting for 3.13. W00T!

hmpf avatar Nov 11 '20 12:11 hmpf

Is there anything preventing a merge of this?

AlexDaniel avatar Jan 12 '21 09:01 AlexDaniel

Is there anything preventing a merge of this?

time to review and merge from the core maintainers side I guess.

REST framework these days is in the somewhat odd position of both being the primary driver of our sponsorships, while also being feature complete and generally not in need of any significant development beyond keeping pace with upcoming Django releases.

Work here probably needs to be focused on good communication aimed at minimising the workload needed to keep the project well maintained.

from https://www.encode.io/reports/december-2020

auvipy avatar Feb 12 '21 13:02 auvipy

could you please fix the tests again?

auvipy avatar Apr 16 '21 09:04 auvipy

@auvipy Tests were failing cause there was a problem with travis (missing six package), I have rebased and pushed my changes.

sevdog avatar Apr 21 '21 13:04 sevdog

@tomchristie probably now is a good time for your review

auvipy avatar Apr 21 '21 14:04 auvipy

This would be really nice in order to have custom Django path converters be used in DRF. Is there any other workarounds without this PR?

phillipuniverse avatar Jul 02 '21 04:07 phillipuniverse

I have done a small refactor removing compatibility for missing path (in test) and replaced default path converter from str to path (which has the same regex which is used by default in routers).

sevdog avatar Jul 23 '21 13:07 sevdog

@auvipy Any issues merging this, running into a similar problem that can be simplified using path converters.

jackton1 avatar Sep 29 '21 14:09 jackton1

@auvipy Any issues merging this, running into a similar problem that can be simplified using path converters. I am not the right person to merge this. @tomchristie @rpkilby they are the maintainers.

auvipy avatar Sep 29 '21 14:09 auvipy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 20:04 stale[bot]

Dear bot, it is still something I need :)

AlexDaniel avatar Apr 17 '22 03:04 AlexDaniel

I think we all need this O:)

auvipy avatar Apr 17 '22 06:04 auvipy

Since it has been more than 2 years since the first draft of this PR, I am start thinking: is there a more elegant way to handle path?

I was wondering if using the include could make the router a bit more usable and reduce string manipulations which could cause hard-to-discover bugs for end users.

This PR is a starting step, but I which the feature could be improved.

sevdog avatar Apr 19 '22 06:04 sevdog

Also waiting for this feature to be merged.

Also, as we are on Django 2.x+, should be the path be the default for SimpleRouter or DefaultRouter?

sshishov avatar Apr 26 '22 21:04 sshishov

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 14 '22 00:07 stale[bot]

still need it

sshishov avatar Jul 14 '22 11:07 sshishov