Support `Decimal` in types, inputs and where filters

Aperta
#575 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
graphql, postgresql, python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
23
Fork
3
Merge medio
10h 6m
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fraiseql/fraiseql-python

Tutte le issue di fraiseql/fraiseql-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.