OpenBB-finance/OpenBB · error · OpenBBError

'congress' is required when 'limit' is set to 0.

Error message

'congress' is required when 'limit' is set to 0.

What it means

OpenBBError raised in the CongressAmendmentsFetcher.aextract_data when limit=0 and amendment_type IS set but congress is None. The 'fetch all' path delegates to get_all_amendments_by_type(congress=..., amendment_type=...), which requires a specific congress number to enumerate; without it the helper cannot paginate. Note the query validator already guarantees amendment_type is present here, so congress is the only missing piece.

Source

Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/models/congress_amendments.py:230

    @staticmethod
    async def aextract_data(
        query: CongressAmendmentsQueryParams,
        credentials: dict[str, str] | None,
        **kwargs: Any,
    ) -> list:
        """Extract data from the Congress API."""
        # pylint: disable=import-outside-toplevel
        import asyncio

        from openbb_congress_gov.utils.helpers import get_all_amendments_by_type
        from openbb_core.provider.utils.errors import UnauthorizedError
        from openbb_core.provider.utils.helpers import amake_request

        api_key = credentials.get("congress_gov_api_key") if credentials else ""

        if query.limit == 0 and query.amendment_type is not None:
            if query.congress is None:
                raise OpenBBError(
                    ValueError("'congress' is required when 'limit' is set to 0.")
                )

            return await get_all_amendments_by_type(
                congress=query.congress,
                amendment_type=query.amendment_type,
            )

        url = f"{base_url}amendment"

        if query.congress is not None:
            url += f"/{query.congress}"

            if query.amendment_type is not None:
                url += f"/{query.amendment_type}"

        url += f"?limit={query.limit if query.limit is not None else 100}"
        url += f"&offset={query.offset if query.offset else 0}"

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Add a congress number: amendments(congress=119, amendment_type='hamdt', limit=0).
  2. If you truly want every congress, loop over the range of congress numbers (e.g. 93–119) with limit=0 each.
  3. Otherwise use a positive limit without congress for the default paged listing.

Example fix

# before
obb.congress.amendments(amendment_type='hamdt', limit=0)

# after
obb.congress.amendments(congress=119, amendment_type='hamdt', limit=0)
Defensive patterns

Strategy: validation

Validate before calling

if limit == 0:
    assert amendment_type in ('hamdt', 'samdt'), 'limit=0 needs amendment_type'
    assert congress is not None and 93 <= int(congress) <= 119, 'limit=0 needs a valid congress number'

Prevention

When it happens

Trigger: Calling obb.congress.amendments(amendment_type='hamdt', limit=0) with no congress argument — the request passes param validation but fails in the fetcher.

Common situations: Users assuming limit=0 + type means 'all congresses'; the two-stage validation (validator allows it, fetcher rejects it) catching people who read only the validator's error message.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/81213734c5fc9bdc. Report an issue: GitHub.