Skip to content

Decimal128Field raise decimal.InvalidOperation error occurs under certain circumstances #212

@euynus

Description

@euynus

When initializing a model with a Decimal128Field in the clickhouse_orm library, a decimal.InvalidOperation error occurs under certain circumstances.

Reproducible Example:

class TestDecimalModel(ClickHouseModel):
    value = fields.Decimal128Field(scale=30, default=0)

a = TestDecimalModel(value=1)

Expected Behavior:

I expected the model TestDecimalModel to be initialized without any errors.

Environment Details:

Python version: 3.8.16
clickhouse_orm version: 2.1.0
Operating System: macOS 14.5

Additional Context:

The error seems to occur specifically when using a Decimal128Field with certain parameters. This issue might be related to how the to_python method handles the value.

from python docs

Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions