marcosschroh / dataclasses-avroschema

Generate avro schemas from python classes. Code generation from avro schemas. Serialize/Deserialize python instances with avro schemas
https://marcosschroh.github.io/dataclasses-avroschema/
MIT License
213 stars 64 forks source link

`.serialize()` does not work with the faust `AvroRecord` class #743

Closed j00bar closed 1 week ago

j00bar commented 1 week ago

Describe the bug The .serialize() method on the hybrid Faust+Avro records throws an error:

TypeError: _asdict() got an unexpected keyword argument 'standardize_factory'

To Reproduce

Using version 0.60.2 with faust-streaming==0.11.2

from dataclasses_avroschema.faust import AvroRecord

class Foo(AvroRecord):
    id: str

record = Foo(id="123")
record.serialize()

Expected behavior

I expected to get the record serialized into Avro (or Avro JSON).

Actual result

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ AvroRecord = <class 'dataclasses_avroschema.faust.main.AvroRecord'>                          │ │
│ │   datetime = <module 'datetime' from                                                         │ │
│ │              '/Users/jag/.pyenv/versions/3.11.9/lib/python3.11/datetime.py'>                 │ │
│ │          f = Foo(id='123')                                                                   │ │
│ │        Foo = <class '__main__.Foo'>                                                          │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /Users/jag/Development/salad-shooter/.direnv/python-3.11/lib/python3.11/site-packages/dataclasse │
│ s_avroschema/schema_generator.py:126 in serialize                                                │
│                                                                                                  │
│   123 │   │   schema = self.avro_schema_to_python()                                              │
│   124 │   │                                                                                      │
│   125 │   │   return serialization.serialize(                                                    │
│ ❱ 126 │   │   │   self.asdict(standardize_factory=standardize_custom_type),                      │
│   127 │   │   │   schema,                                                                        │
│   128 │   │   │   serialization_type=serialization_type,                                         │
│   129 │   │   )                                                                                  │
│                                                                                                  │
│ ╭─────────────────────────────── locals ────────────────────────────────╮                        │
│ │             schema = {                                                │                        │
│ │                      │   'type': 'record',                            │                        │
│ │                      │   'name': 'Foo',                               │                        │
│ │                      │   'fields': [                                  │                        │
│ │                      │   │   {'name': 'id', 'type': 'string'}         │                        │
│ │                      │   ]                                            │                        │
│ │                      }                                                │                        │
│ │               self = Foo(id='123')                                    │                        │
│ │ serialization_type = 'avro'                                           │                        │
│ ╰───────────────────────────────────────────────────────────────────────╯                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: _asdict() got an unexpected keyword argument 'standardize_factory'
marcosschroh commented 1 week ago

Fixed in last release (docs)