8000 Unable to get fastavro to use default value for bytes-decimal logical type · Issue #814 · fastavro/fastavro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to get fastavro to use default value for bytes-decimal logical type #814
Open
@jbwtan

Description

@jbwtan

I have the following snippet

import io
from decimal import Decimal

import fastavro

schema = {
    "type": "record",
    "name": "User",
    "namespace": "com.example",
    "fields": [
        {
            "name": "id",
            "type": "int"
        },
        {
            "name": "paid",
            "type": {
                "type": "bytes",
                "scale": 2,
                "precision": 15,
                "logicalType": "decimal"
            },
            "default": "\u0000"
        },
        {
            "name": "age",
            "type": ["null", "int"],
            "default": None
        }
    ]
}
# works
records = [
    {"id": 1, "age": 30, "paid": Decimal("0.00")},
    {"id": 2, "age": None, "paid": Decimal("0.01")},
]
fastavro.writer(io.BytesIO(), schema, records)

# throws exception
records = [
    {"id": 1, "age": 30},
]
fastavro.writer(io.BytesIO(), schema, records)

fastavro is successful writing records when paid is defined, however i receive an error when trying to write a record when paid is not defined, hoping to use the default value specified in the schema. Please can anyone advise if I am doing something incorrect or have encountered an unexpected issue? I am using fastavro==1.9.7

Many thanks

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

      0