[Django] #32132: ManyToMany field does not respect the PositiveBigIntegerField as ID

42 views
Skip to first unread message

Django

unread,
Oct 22, 2020, 7:41:40 AM10/22/20
to django-...@googlegroups.com
#32132: ManyToMany field does not respect the PositiveBigIntegerField as ID
-------------------------------------+-------------------------------------
Reporter: Kfir | Owner: nobody
Breger |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords: models, orm
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/32132>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 22, 2020, 1:50:15 PM10/22/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

Note that everything works for `BigIntegerField()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:1>

Django

unread,
Oct 22, 2020, 2:10:43 PM10/22/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Kfir Breger):

Thank you for the update. I'll switch to that for now.

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:2>

Django

unread,
Oct 24, 2020, 7:34:50 AM10/24/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:4>

Django

unread,
Oct 25, 2020, 8:52:42 AM10/25/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* needs_tests: 1 => 0


Comment:

Add unit tests and improved the patch. Ready for another round of reviews
:)

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:5>

Django

unread,
Oct 25, 2020, 11:19:38 AM10/25/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1


Comment:

Left some comments regarding the use of `related_fields_match_type` in
tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:6>

Django

unread,
Oct 25, 2020, 5:09:01 PM10/25/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* needs_better_patch: 1 => 0


Comment:

Thanks for the comment Simon! I adapted the tests, please see
https://github.com/django/django/pull/13592#issuecomment-716212270 for
more details

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:7>

Django

unread,
Nov 2, 2020, 3:03:37 AM11/2/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:8>

Django

unread,
Nov 2, 2020, 2:48:14 PM11/2/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: models, orm | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"cfc7cd6513a72b8c5898c264d04bdf49f897a1de" cfc7cd65]:
{{{
#!CommitTicketReference repository=""
revision="cfc7cd6513a72b8c5898c264d04bdf49f897a1de"
Fixed #32132 -- Fixed column types in m2m intermediary tables for
Positive(Big/Small)IntegerFields.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:10>

Django

unread,
Nov 2, 2020, 2:48:14 PM11/2/20
to django-...@googlegroups.com
#32132: ManyToManyField does not respect the PositiveBigIntegerField in m2m
intermediate table.
-------------------------------------+-------------------------------------
Reporter: Kfir Breger | Owner: David
| Wobrock
Type: Bug | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, orm | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"4ebd633350ac07091a23c0f0c3eac3aa691cab05" 4ebd633]:
{{{
#!CommitTicketReference repository=""
revision="4ebd633350ac07091a23c0f0c3eac3aa691cab05"
Refs #32132 -- Added rel_db_type() tests for auto and integer fields.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32132#comment:9>

Reply all
Reply to author
Forward
0 new messages