coddingtonbear/django-measurement

Throw warning for naive measure

Closed this issue · 2 comments

Currently you can set the set a field value using a float. Be default it's assumed that the float is representing the default unit the value is getting saved.

We should throw a warning, about this behaviour and encourage users to set explicit measures.

I think I just ran into this while trying to create a model with using 10 instead of Weight(kg=10);

  File "/foo/lib/python2.7/site-packages/django_measurement/models.py", line 90, in from_db_value
    original_unit=self.get_default_unit(),
  File "/foo/lib/python2.7/site-packages/django_measurement/utils.py", line 14, in get_measurement
    m.unit = original_unit
  File "/foo/lib/python2.7/site-packages/measurement/base.py", line 177, in unit
    unit = aliases[unit]
KeyError: None

Anyway, opened #27 for this.

This is actually implemented since 4a7daae