Evaluating a QuerySet with DecimalField in an EmbeddedModelField crashes

XMLWordPrintableJSON

    • None
    • Python Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Django==5.1.8
      django-mongodb-backend==5.1.0b2

      # app.models
      from django.db import models
      from django_mongodb_backend.fields import EmbeddedModelField
      from django_mongodb_backend.models import EmbeddedModel
      
      class TestEmbeddedModel(EmbeddedModel):
          decimal_field = models.DecimalField(
              max_digits=9, decimal_places=6
          )
      
      
      class TestModel(models.Model):
          embedded_field = EmbeddedModelField(TestEmbeddedModel)
      
      >>> from paying.models import TestModel, TestEmbeddedModel
      >>> embedded_object = TestEmbeddedModel(decimal_field=1)         
      >>> TestModel.objects.create(embedded_field=embedded_object)     
      <TestModel: TestModel object (6808fc0724a581fef9dd0ee6)>
      >>> TestModel.objects.all()
      

      I get this error in retrieving created object.

      Traceback (most recent call last):
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\fields\__init__.py", line 1811, in to_python       
          decimal_value = decimal.Decimal(value)
      TypeError: conversion from Decimal128 to Decimal is not supported
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<console>", line 1, in <module>
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 376, in __repr__
          data = list(self[: REPR_OUTPUT_SIZE + 1])
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 400, in __iter__
          self._fetch_all()
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 1928, in _fetch_all
          self._result_cache = list(self._iterable_class(self))
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\query.py", line 123, in __iter__
          for row in compiler.results_iter(results):
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\sql\compiler.py", line 1512, in apply_converters   
          value = converter(value, expression, connection)
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django_mongodb_backend\fields\embedded_model.py", line 79, in from_db_value
          return self.to_python(value)
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django_mongodb_backend\fields\embedded_model.py", line 91, in to_python
          **{
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django_mongodb_backend\fields\embedded_model.py", line 92, in <dictcomp>
          field.attname: field.to_python(value[field.attname])
        File "C:\Users\Денис\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\fields\__init__.py", line 1813, in to_python       
          raise exceptions.ValidationError(
      django.core.exceptions.ValidationError: ['“1” value must be a decimal number.']
      

            Assignee:
            Tim Graham
            Reporter:
            Денис Жилин
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: