Support `Decimal` in types, inputs and where filters

Offen
#575 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
graphql, postgresql, python

Rechercherichtung

Start in src/fraiseql/core/graphql_type.py, where the issue reports the unsupported output type, then inspect fraiseql.types.Money and its MoneyScalar mapping. The examples named in the issue can show how Decimal annotations are used. Done means Decimal has a defined input and output behavior, or the error points users to Money, with the scalar choice documented next to Money.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

Found while fixing examples for #565.

decimal.Decimal in a @fraiseql.type field fails the schema build with
Unsupported output type: <class 'decimal.Decimal'> (src/fraiseql/core/graphql_type.py).
It is the natural type for money, and about 60 annotations in the examples use it
(enterprise_patterns 26, ecommerce 16, hybrid_tables 6, filtering 5, documented_api/ 4, and
others).

Decimal also fails as an input field (Invalid type passed to convert_type_to_graphql_input: <class 'decimal.Decimal'>), as a query argument, and in generated where inputs:
create_graphql_where_input maps Decimal to DecimalFilter
(src/fraiseql/sql/graphql_where_generator.py:180), whose own Decimal fields can't be built, so
any WhereInput for a type with a Decimal field fails. docs/reference/scalar-types-cheatsheet.md
recommends price: Decimal for money.

fraiseql.types.Money is not a workaround today. It is MoneyField
(src/fraiseql/types/__init__.py:75), which has no entry in convert_scalar_to_graphql
(src/fraiseql/types/scalars/graphql_utils.py), so it fails the same way:
Unsupported output type: <class 'fraiseql.types.scalars.money.MoneyField'>. This is general:
only 11 of the 53 scalar markers exported from fraiseql.types are mapped (to be filed
separately). Only the raw price: MoneyScalar builds, and it can't be made optional
(MoneyScalar | None is a TypeError) and silently rounds to 4 places.

Proposal: add a Decimal scalar (serialized as a string, parsed to Decimal; not Float, which
loses precision for money), mapped from decimal.Decimal for output, input and DecimalFilter.
Check that the JSONB passthrough path keeps precision (psycopg may already load JSONB numbers as
float). Don't point the error at Money until Money itself works.


Edited 2026-10-21 after an independent re-check on 419569fa: Decimal also fails as input, argument and in WhereInput; fraiseql.types.Money fails the same way, so it's not a workaround. Relabelled bug.

Vorherrschende Sprache
Python
Sterne
23
Forks
3
Ø Merge
10 Std. 6 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fraiseql/fraiseql-python

Alle Issues in fraiseql/fraiseql-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.