Marshal With is expecting the params in reponse · Issue #618 · python-restx/flask-restx · GitHub
Skip to content

Marshal With is expecting the params in reponse #618

Open

Description

@fras2560

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!

Activity

  1. chinmay655 commented on Jul 9, 2026

    @chinmay655

    Hi! I'd like to work on this issue if it's still available.

  2. chinmay655 commented on Jul 9, 2026

    @chinmay655

    Hi! I investigated this issue locally.

    I was able to reproduce the behavior by adding a regression test with a route that has two required path parameters (similar to /int:year/int:league_id).

    The exception originates from flask_restx.fields.Url.output(), where url_for() is called:

    url_for(endpoint, _external=self.absolute, **data)

    When the marshalled object does not contain the required route parameters, Flask raises a BuildError. Currently, Url.output() only catches TypeError and wraps it as MarshallingError, so the BuildError propagates.

    Before preparing a PR, I'd like to clarify the expected behavior:

    Should this case also be wrapped as a MarshallingError, or is propagating BuildError the intended behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions