Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HyperlinkRelated creating invalid endpoint #240

Open
Makistos opened this issue Nov 24, 2021 · 1 comment
Open

HyperlinkRelated creating invalid endpoint #240

Makistos opened this issue Nov 24, 2021 · 1 comment

Comments

@Makistos
Copy link

Makistos commented Nov 24, 2021

For some reason HyperlinkRelated seems to create an invalid endpoint with HyperlinkRelated which Flask rejects:

Exception has occurred: BuildError (note: full exception trace is shown but execution is paused at: api_GetMagazine) Could not build url for endpoint '/api/publishers' with values ['id']. Did you mean 'publishers' instead?

These are my models:

class MagazineSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Magazine
    id = ma.auto_field()
    name = ma.auto_field()
    publisher = ma.HyperlinkRelated(
        endpoint='/api/publishers')
class PublisherSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Publisher
    id = ma.auto_field()

And this is what that API looks like:

@app.route('/api/publishers/<id>', methods=['get'])
def api_GetPublisher(id: Any) -> Any:
    options = {}
    options['publisherId'] = id
    return GetPublisher(options)

This API works with curl.

And this is how I try to dump the results in GetPublisher:

schema = MagazineSchema()
retval = schema.dump(magazine)

Am I doing something wrong? I can't figure out what that could be. I tried both with AutoSchema and Schema and both give the same result.

@Makistos
Copy link
Author

I did figure it out which leaves me with an issue: if I give the view name the url is wrong (/publishers/) rather than the one shown above. Oh well, I guess I have to either add a URI field by hand or create it in the front-end from the id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant