flask-marshmallow icon indicating copy to clipboard operation
flask-marshmallow copied to clipboard

UrlFor fields include all passed params in url.

Open tinproject opened this issue 7 years ago • 6 comments

UrlFor fields use all the passed parameters of the field in construct the url, this makes those fields unsuitable to use with apispec in the same way as other marshmallow fields, or with any information at all.

Example:

    image_url = URLFor(
        endpoint='return_image_file',
        id='<id>',
        required=True,
        description='url location of the image file.',
    )

Result:

"image_url": "/api/image/191.png?description=url+location+of+the+image+file.&required=True",

Perhaps the best way to avoid this is define a new argument in the fields: endpoint_params, for example, to store a dict with all the endpoint parameters. For backward compatibility it can look for the existence of that argument and if exists use the parameters of the dict inside, if not use the parameters of the field as is currently done.

tinproject avatar Nov 16 '16 21:11 tinproject

Totally agree with that ...

Is there a special reason for this behaviour?

dhofstetter avatar Dec 01 '17 13:12 dhofstetter

I agree that the current behavior isn't ideal. I would certainly review and merge a PR fixing this. I like @tinproject 's idea of using a different argument to specify url_for arguments. Perhaps it should be named values for consistency with the url_for API.

sloria avatar Dec 01 '17 15:12 sloria

Something like that I actually used now within my project, just inherited the existing fields and adding a dict parameter that takes all the arguments for url_for.

That is good so far, and now I'm perfectly fine with defining all the stuff I need to document my stuff as expected without getting this weird params within the url.

dhofstetter avatar Dec 01 '17 15:12 dhofstetter

A temporary solution that I followed was using "post_dump" decorator to remove the params. Not an ideal solution but gets the job done. @sloria can you share the relevant PR

AlrasheedA avatar Mar 08 '20 15:03 AlrasheedA

Any updates on this issue?

alexschoeberl avatar Sep 15 '20 16:09 alexschoeberl

No updates from me. I won't have time to work on this myself in the near future, but I would review and merge a PR implementing the behavior described above.

sloria avatar Sep 15 '20 16:09 sloria