agateblue / agateblue/django-dynamic-preferences

FloatPreference should be able to be initialized from both floats and ints

未关闭
#265 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
359
派生
86
PR 合并指标
30 天内没有已合并 PR

描述

Recently I met a problem with setting a `FloatPrefeerence` to an int value instead of its float equivalent (`1` instead of `1.0`), which sounds reasonable, but I got this error:

```
File "/app/.venv/lib/python3.10/site-packages/dynamic_preferences/models.py", line 53, in set_value
self.raw_value = self.preference.serializer.serialize(value)
File "/app/.venv/lib/python3.10/site-packages/dynamic_preferences/serializers.py", line 39, in serialize
return cls.to_db(value, **kwargs)
File "/app/.venv/lib/python3.10/site-packages/dynamic_preferences/serializers.py", line 54, in to_db
return text_type(cls.clean_to_db_value(value))
File "/app/.venv/lib/python3.10/site-packages/dynamic_preferences/serializers.py", line 163, in clean_to_db_value
raise cls.exception('FloatSerializer can only serialize Float instances')
```

`FloatSerializer` should INMHO accept ints as well, for more flexibility in user input

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。