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

Marshal With is expecting the params in reponse #618

Open
fras2560 opened this issue Sep 14, 2024 · 0 comments
Open

Marshal With is expecting the params in reponse #618

fras2560 opened this issue Sep 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fras2560
Copy link

I am writing an endpoint where two params are part of the url

Code

schedule_api = Namespace(
    "schedule",
    description="API for all the League's Schedule queries"
)
schedule_payload = schedule_api.model('Schedule', {
    'away_team': fields.String(
        description="The name of the away team",
    ),
    'away_team_id': fields.Integer(
        description="The id of the away team",
    ),
    'date': fields.Date(
        description="The date of the game",
    ),
    'field': fields.String(
        description="The field of the game",
    ),
    'home_team': fields.String(
        description="The name of the home team",
    ),
    'home_team_id': fields.Integer(
        description="The id of the home team",
    ),
    'league_id': fields.Integer(
        description="The id of the league",
    ),
    'score': fields.String(
        description="The score of the game if played",
    ),
    'status': fields.String(
        description="The status of the game",
    ),
    'time': fields.String(
        description="The time of the game (Format: HH-MM)",
        example="12:01"
    ),
})
pagination = get_pagination(schedule_api)
schedule_pagination = schedule_api.inherit("SchedulePagination", pagination, {
    'items': fields.List(fields.Nested(schedule_payload))
})
@schedule_api.route("/<int:year>/<int:league_id>", endpoint="rest.schedule")
@schedule_api.doc(
    params={"year": "The schedule year", "league_id": "The id of the league"}
)
class ScheduleAPIX(Resource):

    @schedule_api.marshal_with(schedule_pagination, envelope='resource')
    def get(self, year, league_id):
        page = request.args.get('page', 1, type=int)
        data = pull_schedule(year, league_id, page=page)
        # running into issue where say this was needed in response
        # just added them for now
        data['year'] = year
        data['league_id'] = league_id
        return data

Repro Steps (if applicable)

  1. ...
  2. ...
  3. Broken!

Expected Behavior

Should be able to not include league_id and year in the response

Actual Behavior

[A description of the unexpected, buggy behavior.](root:errors_handler.py:86 Could not build url for endpoint 'rest.schedule' with values ['has_next', 'has_prev', 'items', 'pages', 'total']. Did you forget to specify values ['league_id', 'year']?)

Error Messages/Stack Trace

[A description of the unexpected, buggy behavior.](root:errors_handler.py:86 Could not build url for endpoint 'rest.schedule' with values ['has_next', 'has_prev', 'items', 'pages', 'total']. Did you forget to specify values ['league_id', 'year']?)

Environment

  • Python version 3.10.12
  • Flask version 2.2.3
  • Flask-RESTX version 1.3.0
  • Other installed Flask extensions

Additional Context

image
image

This is your last chance to provide any pertinent details, don't let this opportunity pass you by!

@fras2560 fras2560 added the bug Something isn't working label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant