Opened 4 years ago
Closed 4 years ago
#32132 closed Bug (fixed)
ManyToManyField does not respect the PositiveBigIntegerField in m2m intermediate table.
Reported by: | Kfir Breger | Owned by: | David Wobrock |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Normal | Keywords: | models, orm |
Cc: | David Wobrock | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When creating a relation between 2 models using PositiveBigIntegerField on Postgresql, the relation table is created using regular ints as the column type. This in turn leads to out of bound error when using large numbers for ids.
from django.contrib.gis.db import models class Node(models.Model): id = models.PositiveBigIntegerField(primary_key=True) point = models.PointField() class Relation(models.Model): id = models.PositiveBigIntegerField(primary_key=True) nodes = models.ManyToManyField(Node)
The generated table will look like this:
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description -------------+---------+-----------+----------+------------------------------------------------+---------+--------------+------------- id | integer | | not null | nextval('osm_relation_nodes_id_seq'::regclass) | plain | | relation_id | integer | | not null | | plain | | node_id | integer | | not null | | plain | |
As you can see, the PositiveBigInteger is not respected and a regular int is set
Change History (10)
comment:1 by , 4 years ago
Summary: | ManyToMany field does not respect the PositiveBigIntegerField as ID → ManyToManyField does not respect the PositiveBigIntegerField in m2m intermediate table. |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 4 years ago
Cc: | added |
---|---|
Has patch: | set |
Owner: | changed from | to
Status: | new → assigned |
Hi!
I tried to tackle this issue, since it doesn't seem to complicated as a first glance :)
PR: https://github.com/django/django/pull/13592
comment:4 by , 4 years ago
Needs tests: | set |
---|
comment:5 by , 4 years ago
Needs tests: | unset |
---|
Add unit tests and improved the patch. Ready for another round of reviews :)
comment:6 by , 4 years ago
Patch needs improvement: | set |
---|
Left some comments regarding the use of related_fields_match_type
in tests.
comment:7 by , 4 years ago
Patch needs improvement: | unset |
---|
Thanks for the comment Simon! I adapted the tests, please see https://github.com/django/django/pull/13592#issuecomment-716212270 for more details
comment:8 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thanks for the report.
Note that everything works for
BigIntegerField()
.