marshmallow-code / marshmallow-code/flask-marshmallow

HyperlinkRelated creating invalid endpoint

Open
#240 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
887
Forks
65
Avg merge
7h 25m
Merged PRs (30d)
3

Description

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/', 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading HyperlinkRelated in the schema definitions and compare its endpoint handling with the api_GetPublisher route shown in the issue. Reproduce the schema.dump(magazine) call and inspect the generated endpoint name and URL values. Done means dumping a magazine produces a valid publisher hyperlink accepted by Flask.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python, sqlalchemy
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.