Django integer fields gets transformed to Float?
See original GitHub issueOn a project of mine I noticed this unexpected behavior:
Using graphene_django
with graphene.relay
converts IntegrierField
s of my models to graphene.Float
properties in the API, e.g.:
class Incident(models.Model):
incident_id = models.IntegerField(unique=True)
class IncidentType(graphene_django.types.DjangoObjectType):
class Meta:
model = Incident
interfaces = (graphene.relay.Node,)
filter_fields = {
'incident_id': ['exact'],
}
class Query:
incident = graphene.relay.Node.Field(IncidentType)
incidents = DjangoFilterConnectionField(IncidentType)
To be precise, using the incident
attribute shows the incidentId
to be of type Int
. But using the incidents
attribute suggests that incidentId
is of type Float
.
I’d like to point out, that there is no error occurring, but it strikes me as weird.
I observed this with:
- Django 2.2
- django-filter 2.1.0
- graphene 2.1.3
- graphene-django 2.2.0
- graphql-core 2.1
- graphql-relay 0.4.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
How do I get Django to display integers instead of floats
Main problem is to know when a float is meant to be an integer (instead of being only near an integer value). If...
Read more >Model field reference - Django documentation
An IntegerField that automatically increments according to available IDs. You usually won't need to use this directly; a primary key field will ...
Read more >6 Ways to Convert String to Float in Python - FavTutor
You can use the float() function to convert any data type into a floating-point number. This method only accepts one parameter. If you...
Read more >Numeric field types - OpenSearch documentation
A scaled float field type is a floating-point value that is multiplied by the scale factor and stored as a long value. It...
Read more >Model Field - Django ORM Working - Part 2
For example, to_python for IntegerField will convert the value to Python integer. The original value could be string or float . Every field...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same problem as @Gamsake here, with 2.15.0. The problem seems to occur when using
filter_fields
on a django model’sid
column.Our workaround is to define and set an explicit filterset class:
@jkimbo Yes. I’m using 2.4.0 the latest now and ‘id’ the field of my model has Int type, but it is converted into Float type. Exactly same issue as above first post. I’ve done triple checks but i never solve this problem. any clue plz.