Skip to content

Migration guide ​

Every breaking release has its own section below, newest first. If you are crossing several releases at once, work from the bottom of the page upwards.

Upgrading to v0.16.0 (from v0.15.x) ​

  • 0.150.16
    pydantic.missing, pydantic.missing_argument, pydantic.missing_keyword_only_argument, pydantic.missing_positional_only_argumentfastapi-viewsets.required
    pydantic.string_too_short, pydantic.too_short, pydantic.bytes_too_short {min_length}fastapi-viewsets.min_length {minLength}
    pydantic.string_too_long, pydantic.too_long, pydantic.bytes_too_long, pydantic.url_too_long {max_length}fastapi-viewsets.max_length {maxLength}
    pydantic.greater_than_equal {ge}fastapi-viewsets.min_value {minValue}
    pydantic.greater_than {gt}fastapi-viewsets.min_value_exclusive {minValue}
    pydantic.less_than_equal {le}fastapi-viewsets.max_value {maxValue}
    pydantic.less_than {lt}fastapi-viewsets.max_value_exclusive {maxValue}
    pydantic.multiple_of {multiple_of}fastapi-viewsets.multiple_of {multipleOf}
    pydantic.decimal_max_digits {max_digits}fastapi-viewsets.max_digits {maxDigits}
    pydantic.decimal_max_places {decimal_places}fastapi-viewsets.max_decimal_places {maxDecimalPlaces}
    pydantic.decimal_whole_digits {whole_digits}fastapi-viewsets.max_whole_digits {maxWholeDigits}
    pydantic.string_pattern_mismatch {pattern}fastapi-viewsets.pattern {pattern}
    pydantic.enum, pydantic.literal_error {expected}fastapi-viewsets.in_allowed_values {allowedAsText}
    pydantic.int_type, pydantic.int_parsing, pydantic.int_parsing_size, pydantic.int_from_floatfastapi-viewsets.invalid_integer
    pydantic.float_*, pydantic.finite_number, pydantic.decimal_type, pydantic.decimal_parsing, pydantic.fraction_*fastapi-viewsets.invalid_number
    pydantic.bool_*fastapi-viewsets.invalid_boolean
    pydantic.date_type, pydantic.date_parsing, pydantic.date_from_datetime_*fastapi-viewsets.invalid_date
    pydantic.time_type, pydantic.time_parsingfastapi-viewsets.invalid_time
    pydantic.datetime_type, pydantic.datetime_parsing, pydantic.datetime_object_invalid, pydantic.datetime_from_date_parsingfastapi-viewsets.invalid_datetime
    pydantic.time_delta_*fastapi-viewsets.invalid_duration
    pydantic.url_type, pydantic.url_parsing, pydantic.url_syntax_violationfastapi-viewsets.invalid_url
    pydantic.uuid_type, pydantic.uuid_parsingfastapi-viewsets.invalid_uuid
    pydantic.date_past, pydantic.datetime_past / pydantic.date_future, pydantic.datetime_futurefastapi-viewsets.past / fastapi-viewsets.future
    pydantic.string_type, pydantic.string_unicode, pydantic.bytes_type, pydantic.dict_type, pydantic.frozen_dict_type, pydantic.ordered_dict_type, pydantic.counter_type, pydantic.list_type, pydantic.tuple_type, pydantic.set_type, pydantic.frozen_set_type, pydantic.deque_type, pydantic.mapping_type, pydantic.iterable_type, pydantic.model_type, pydantic.model_attributes_type, pydantic.dataclass_type, pydantic.dataclass_exact_type, pydantic.named_tuple_type, pydantic.none_required, pydantic.arguments_type, pydantic.callable_type, pydantic.is_instance_of, pydantic.is_subclass_offastapi-viewsets.invalid_type
    pydantic.value_error, pydantic.assertion_error {error}fastapi-viewsets.invalid {} (the text is in detail)

    An error from the invalid_*, invalid_type or in_allowed_values rows with a null input becomes fastapi-viewsets.required. Other pydantic types remain pydantic.<type>.

  • python
    settings.viewsets_tag_name = lambda cls: cls.__name__.removesuffix("ViewSet")

Upgrading to v0.15.0 (from v0.14.x) ​

  • python
    # 0.14
    async def perform_destroy(self, context, pk: str) -> dict:
        record = await reset_setting(pk)
        return record.model_dump()
    
    # 0.15
    @__router.post("{pk}/reset")
    async def reset(self, context: Context, pk: str) -> Setting:
        return await reset_setting(pk)
    ts
    reset(pk: string) {
      return this.request<Setting>('POST', `/${pk}/reset`);
    }

    See custom endpoints and TS custom endpoints.

  • ts
    // 0.14
    await api.bulkDestroy(pks); // DestroyReturnData[]; throws on the first missing key
    
    // 0.15
    const result = await api.bulkDestroy(pks); // BulkDestroyReturnData<K>
    const failed = Object.entries(result).filter(([, error]) => error !== null);

Upgrading to v0.14.0 (from v0.13.x) ​

Upgrading to v0.13.0 (from v0.12.x) ​

  • python
    # 0.12
    async def setup_lookup_filter(self, fltr):
        self._ids = fltr.ids
    
    async def perform_lookup(self, context):
        return [to_item(tag) for tag in Tag.objects.filter(id__in=self._ids)]
    
    # 0.13
    async def perform_lookup(self, context):
        return Tag.objects.all()
    
    async def apply_lookup_filter(self, context, query, records):
        if query.has_filter and query.fltr.ids:
            records = records.filter(id__in=query.fltr.ids)
            query.mark_applied("filter")
        return await super().apply_lookup_filter(context, query, records)
    
    def to_lookup_item(self, raw):
        return to_item(raw)

Upgrading to v0.12.0 (from v0.11.x) ​

  • 0.110.12
    not_foundfastapi-viewsets.not_found
    read_onlyfastapi-viewsets.read_only
    session_expiredfastapi-viewsets.session_expired
    not_authorizedfastapi-viewsets.not_authorized
    rate_limitedfastapi-viewsets.rate_limited
    result_timeoutfastapi-viewsets.result_timeout
    result_reader_stoppedfastapi-viewsets.result_reader_stopped
    action_dispatch_failedfastapi-viewsets.action_dispatch_failed
    action_interruptedfastapi-viewsets.action_interrupted
    action_failedfastapi-viewsets.action_failed
    idempotency_key_invalidfastapi-viewsets.idempotency_key_invalid
    idempotency_key_reusedfastapi-viewsets.idempotency_key_reused
    unsupported_list_shapefastapi-viewsets.unsupported_list_shape
    event_topic_invalidfastapi-viewsets.event_topic_invalid
    event_topic_refusedfastapi-viewsets.event_topic_refused
    event_scope_missingfastapi-viewsets.event_scope_missing
    event_subscriptions_exceededfastapi-viewsets.event_subscriptions_exceeded
    event_cursors_exceededfastapi-viewsets.event_cursors_exceeded
    cursor_unreadablefastapi-viewsets.cursor_unreadable
    cursor_missing_positionfastapi-viewsets.cursor_missing_position
    cursor_stalefastapi-viewsets.cursor_stale
    cursor_missing_keysfastapi-viewsets.cursor_missing_keys
    cursor_value_mismatchfastapi-viewsets.cursor_value_mismatch

One error body ​

Every error of a viewset's route is answered with one body, ApiErrorBody, over REST and muxws, without a handler registered by the application (see Error codes → The error body):

json
{ "detail": "...", "detail_code": "<namespace>.<code>", "detail_params": {}, "field_errors": {} }
  • python
    # before
    from fastapi_viewsets.exceptions import DfViewSetError, df_viewset_exception_handler
    
    app.add_exception_handler(DfViewSetError, df_viewset_exception_handler)
    
    # after
    from fastapi_viewsets.error_responses import install_error_handlers
    
    install_error_handlers(app)
  • Error0.11 body0.12 body
    NotFoundError(42), handler registered{"detail": "Item with pk 42 not found", "detail_code": "not_found", "detail_params": {"pk": 42}}{"detail": "Item with pk 42 not found", "detail_code": "fastapi-viewsets.not_found", "detail_params": {"pk": 42}, "field_errors": {}}
    NotFoundError(42), no handler{"detail": "Item with pk 42 not found"}the same as above
    a request that fails validation{"detail": [{"type": "string_too_short", "loc": ["body", "name"], "msg": "String should have at least 3 characters", "input": "a", "ctx": {"min_length": 3}}]}{"detail": "The request failed validation", "detail_code": "fastapi-viewsets.validation_failed", "detail_params": {}, "field_errors": {"name": [{"code": "pydantic.string_too_short", "params": {"min_length": 3}, "detail": "String should have at least 3 characters"}]}}
    raise HTTPException(403, "Not your item"){"detail": "Not your item"}{"detail": "Not your item", "detail_code": "fastapi-viewsets.http_error", "detail_params": {"status": 403}, "field_errors": {}}
    raise HTTPException(400, {"field": "x"}){"detail": {"field": "x"}}{"detail": "Bad Request", "detail_code": "fastapi-viewsets.http_error", "detail_params": {"status": 400, "detail": {"field": "x"}}, "field_errors": {}}
    an exception without a handlerplain text Internal Server Error{"detail": "Internal Server Error", "detail_code": "fastapi-viewsets.unhandled_error", "detail_params": {}, "field_errors": {}}
    a muxws command with headers no route matches{"detail": ":path must be absolute, got 'tracks'"} (400){"detail": ":path must be an absolute path", "detail_code": "fastapi-viewsets.command_invalid", "detail_params": {"reason": "path_relative"}, "field_errors": {}} (400)
    an exception before a muxws command's responsepayload null (500)the body of fastapi-viewsets.unhandled_error (500)

    The response of an exception without a handler no longer contains its text; the exception is re-raised and logged by the server as before. A handler the application registered for an exception class, a status, HTTPException, or Exception / 500 keeps answering as it did.

  • jsonc
    // 0.11
    {"rev": null, "events": null, "error": "fastapi-viewsets.event_topic_refused", "status": 403}
    // 0.12
    {"rev": null, "events": null, "error": {"detail": "Topic org:9 is not admitted", "detail_code": "fastapi-viewsets.event_topic_refused", "detail_params": {"topic": "org:9"}, "field_errors": {}}, "status": 403}

    The event client reports it as a ViewSetRequestError of status whose response.data is that body. Deploy the frontend and the backend together: a 0.12 event client leaves a topic answered with a code string unanswered, and a 0.11 one leaves a topic answered with a body unanswered.

  • ts
    // before
    const body = error.response?.data;
    if (error.response?.status === 422) toFieldErrors(body as FieldErrorsBody);
    else if (typeof body?.detail === 'string') toErrorDescription(body as ApiErrorBody);
    
    // after
    const body = errorBodyOf(error);
    toFieldErrors(body); // {} for an error without field errors
    toErrorDescription(body);

Upgrading to v0.11.0 (from v0.10.x) ​

Upgrading to v0.10.0 (from v0.9.x) ​

Upgrading to v0.9.0 (from v0.8.x) ​

Upgrading to v0.8.0 (from v0.7.x) ​

The npm package no longer translates errors and no longer depends on @dynamicforms/translatable. It converts an error body into an ErrorDescription, and the application translates it by its code with the function it uses for its vue-forms errors. The response bodies are unchanged.

  • ts
    // before
    translateStrings((key) => myTranslations[key]);
    const message = translateApiError(body);
    
    // after
    const message = errorText(toErrorDescription(body));

    errorText is the application's function described in vue-forms: Error messages and translation. It looks the code up in the application's translations, substitutes params and falls back to detail. Add the codes listed in Error codes to the translations; the placeholder names are the same.

Upgrading to v0.6.0 (from v0.5.7) ​

Nothing about a response body changes unless you opt in. There is no checklist for this release - see Error codes for what changed and how to opt into it.

NotFoundError moves from fastapi_viewsets.response_classes to fastapi_viewsets.exceptions:

python
# before
from fastapi_viewsets.response_classes import NotFoundError

# after
from fastapi_viewsets.exceptions import NotFoundError

Released under the MIT License.