fastapi-pagination icon indicating copy to clipboard operation
fastapi-pagination copied to clipboard

Unclear Breaking change in fastapi-pagination 0.13.0

Open Mulugruntz opened this issue 8 months ago • 2 comments

Hi,

See this diff:


    LimitOffsetPaginatedResponse_CountryResponse_:
      properties:
        details:
          items:
            $ref: '#/components/schemas/CountryResponse'
          title: Details
          type: array
        limit:
          anyOf:
          - minimum: 1.0
            type: integer
          - type: 'null'
          title: Limit
        links:
          $ref: '#/components/schemas/Links'
+         readOnly: true
        message:
          title: Message
          type: string
        offset:
          anyOf:
          - minimum: 0.0
            type: integer
          - type: 'null'
          title: Offset
        total:
          anyOf:
          - minimum: 0.0
            type: integer
          - type: 'null'
          title: Total
      required:
      - details
-     - total
      - limit
      - offset
-     - links
      - message
+     - links
      title: LimitOffsetPaginatedResponse[CountryResponse]
      type: object

Basically, it seems that there are 2 changes:

  • total used to be required but nullable. Now, its key is no longer required.
  • links are now readOnly.

And here is the code I use

from fastapi import Query
from fastapi_pagination.customization import (
    CustomizedPage,
    UseAdditionalFields,
    UseFieldsAliases,
    UseIncludeTotal,
    UseName,
    UseParamsFields,
)
from fastapi_pagination.links import LimitOffsetPage

customizers = [
    UseFieldsAliases(
        items="details",  # `details` contains the list of items.
    ),
    UseAdditionalFields(
        message=str,  # `message` is always there, for all `BaseGenericResponse`.
    ),
    UseIncludeTotal(True),
]

T = TypeVar("T")

GenericLimitOffsetPaginatedResponse = CustomizedPage[
    LimitOffsetPage[T],
    UseName("LimitOffsetPaginatedResponse"),
    UseParamsFields(
        limit=Query(10, ge=1, le=100, description="Page size limit"),
        offset=Query(0, ge=0, description="Page offset"),
    ),
    *customizers,
]

then

from fastapi_pagination import paginate
from pydantic import BaseModel

class CountryResponse(BaseModel):
    ...

class CountryService:
    # Type of `self._all_countries: list[CountryResponse]`
    # ...
    def get_all_countries(self) -> GenericLimitOffsetPaginatedResponse[CountryResponse]:
        return paginate(self._all_countries, safe=True, additional_data={"message": "OK"})

I checked the changelog (which only contains a link to the migration guide), tried to figure out what I should change to not break. But it's unclear to me. What should I amend?

Was a default changed by mistake?

Also, it's just a thought, but it may be worth having a sample app and dumping its yaml.safe_dump(sample_app.openapi(), indent=2) and detect if a breaking change was introduced in existing features.

Mulugruntz avatar Apr 28 '25 16:04 Mulugruntz

Hi @Mulugruntz,

Sorry for long response.

I guess this issue was added in https://github.com/uriyyo/fastapi-pagination/pull/1505

uriyyo avatar May 06 '25 21:05 uriyyo

I like your idea of adding tests for OpenAPI schema, it makes sense to me, thanks 🙏

uriyyo avatar May 06 '25 21:05 uriyyo

Hi @Mulugruntz,

It's been a long time, and I hope we solved this issue.

Starting from 0.14.0 version total field becomes required by default for non-optional pages, also we added checks for openapi schema changes.

Beta version v0.14.0b1 has been released, I would appreciate any feedback 🙏

uriyyo avatar Jul 26 '25 11:07 uriyyo

Thank you Yurii.

I will try (maybe next week), and if it works, I'll remove fastapi-pagination from the Renovate exclusion list. And I'll come back here and give you some feedback :)

Mulugruntz avatar Jul 26 '25 12:07 Mulugruntz

also we added checks for openapi schema changes.

Can you point me to the PR(s) that tackled this? Thank you!

Mulugruntz avatar Jul 26 '25 12:07 Mulugruntz

Here is commit - https://github.com/uriyyo/fastapi-pagination/commit/eacf6ba93da9e71179324336281800d430a937ac

uriyyo avatar Jul 26 '25 12:07 uriyyo

Hi @Mulugruntz,

Can I close this issue?

uriyyo avatar Sep 03 '25 10:09 uriyyo

Hi @Mulugruntz,

I'm closing this issue, let me know if you still have any issues.

uriyyo avatar Sep 27 '25 09:09 uriyyo