Open ckarli opened 10 months ago
Interesting. I was not aware of that new field type. Will have to investigate on how to handle the field. Seems like output_field
is pretty much the only option for extraction.
We are getting the same error using GeneratedField.
TypeError: DecimalField.__init__() missing 2 required positional arguments: 'max_digits' and 'decimal_places'
I meet the similar error using 'GeneratedField' with 'DecimalField'
TypeError: DecimalField.__init__() missing 2 required positional arguments: 'max_digits' and 'decimal_places'
class Product(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=5, decimal_places=2)
number = models.IntegerField()
description = models.TextField()
release_date = models.DateField()
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)
ERROR_in_swaggerUI = models.GeneratedField(
expression=F("price") * F("number"),
output_field=models.DecimalField(max_digits=15, decimal_places=2),
db_persist=True,
)
OK_in_swaggerUI = models.GeneratedField(
expression=F("price") * F("number"),
output_field=models.FloatField(),
db_persist=True,
)
Everything is ok if we comment out the "ERROR_in_swaggerUI" above
Sry this kinda fell of the waggon. I did indeed tried to parse this field for some time, but I turned out to be weirdly complicated.
I will make another attempt at this, but if it does not work out, at least we should fall back to a str
default and not raise any exceptions until we can figure out a better solution.
Describe the bug Types can't be extracted from newly added GeneratedField. Field must be added explicitly to the serializer with the correct type as defined in the "output_field". Otherwise it gives the error below.
To Reproduce
Use GeneratedField in a model, and use this model in a ModelSerializer's fields parameter.
class InvoiceSerializer(serializers.ModelSerializer):
Expected behavior Field type must be inferred from output_field