faust icon indicating copy to clipboard operation
faust copied to clipboard

Custom coercions no longer working starting in v1.10.0

Open mcbex opened this issue 6 years ago • 3 comments

Checklist

  • [x] I have included information about relevant versions
  • [ ] I have verified that the issue persists when using the master branch of Faust.
    • Confirmed issue exists in latest release (1.10.3)

Steps to reproduce

When attempting to upgrade from Faust 1.6.0 I noticed custom coercions defined on my models are no longer being called. I reproduced this in v1.10.0 but did not try any of the 1.9.* versions after 1.9.0.

Steps to reproduce:

using Faust v1.9.0 (works as expected)

>>> from faust import Record
>>> def coercion_handler(input):
...     return 'junk'
...
>>> class MyJunkModel(Record, coercions={str: coercion_handler}):
...     junk: str
...
>>> x = MyJunkModel(junk=1)
>>> x
<MyJunkModel: junk='junk'>

using Faust v1.10.3 (does not work as expected)

>>> from faust import Record
>>> def coercion_handler(input):
...     return 'junk'
...
>>> class MyJunkModel(Record, coercions={str: coercion_handler}):
...     junk: str
...
>>> x = MyJunkModel(junk=1)
>>> x
<MyJunkModel: junk=1>

When reproducing in an IDE with a debugger in the coercion handler in v1.10.3 the handler seems as though it is never called.

Versions

  • Python version: 3.6.5
  • Faust version: 1.10.0/1.10.3
  • Operating system: Mac OSX 10.14
  • Kafka version: NA
  • RocksDB version (if applicable)

mcbex avatar Mar 30 '20 22:03 mcbex

Interestingly, if I add coerce=True to the model, the value will be coerced to the type that it was defined with, but it still does not use the custom handler:

>>> class MyOtherJunkModel(Record, coerce=True, coercions={str: coercion_handler}):
...     junk: str
...
>>> y = MyOtherJunkModel(junk=1)
>>> y
<MyOtherJunkModel: junk='1'>

Notice that here I passed in int and it has correctly been coerced to str but not using the handler as I would expect.

I hope this feature hasn't been deprecated as I use it heavily and find it to be a really elegant solution for cleaning and transforming some types of data.

mcbex avatar Mar 30 '20 22:03 mcbex

I too would like to be able to perform custom coercions - I wasn't using faust prior to v1.10, but I would like to use this for, e.g., UUID standardization at the Record level.

jmaroeder avatar Sep 14 '20 18:09 jmaroeder

+1

dada-engineer avatar Jan 11 '22 10:01 dada-engineer