[Django] #33187: Foreign key to a specific field is not handled in inspected

69 views
Skip to first unread message

Django

unread,
Oct 11, 2021, 5:12:50 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspected
-------------------------------------------+------------------------
Reporter: Thierry Bastian | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
if you have a DB like that

CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);

CREATE TABLE bar ( id serial primary key, other_id int,
constraint myconst
FOREIGN
KEY(other_id) references foo(other_id)
);


the generated model for the bar table will have the other_id be a FK to
foo and not foo(other_id).

I'm attaching a potential fix for this. Sorry I had no time for the UTs.

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

Django

unread,
Oct 11, 2021, 5:13:27 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspected
---------------------------------+--------------------------------------

Reporter: Thierry Bastian | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Thierry Bastian):

* Attachment "handle_fk_to_field.diff" added.

simple patch to handle FK to non pk field.

Django

unread,
Oct 11, 2021, 5:16:19 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspected
---------------------------------+--------------------------------------

Reporter: Thierry Bastian | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Thierry Bastian):

* status: new => closed
* resolution: => invalid


Comment:

it seems I cannot reproduce outside of my own code...

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

Django

unread,
Oct 11, 2021, 5:21:04 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspected
---------------------------------+--------------------------------------

Reporter: Thierry Bastian | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Thierry Bastian):

* status: closed => new
* resolution: invalid =>


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

Django

unread,
Oct 11, 2021, 5:52:07 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------

Reporter: Thierry Bastian | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* component: Uncategorized => Database layer (models, ORM)


Old description:

> if you have a DB like that
>
> CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);
>
> CREATE TABLE bar ( id serial primary key, other_id int,
> constraint myconst
> FOREIGN KEY(other_id) references foo(other_id)
> );
>

> the generated model for the bar table will have the other_id be a FK to
> foo and not foo(other_id).
>
> I'm attaching a potential fix for this. Sorry I had no time for the UTs.

New description:

if you have a DB like that

{{{#!sql


CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);

CREATE TABLE bar (
id serial primary key, other_id int,
constraint myconst
FOREIGN KEY(other_id) references foo(other_id)
);
}}}

the generated model for the bar table will have the other_id be a FK to
foo and not foo(other_id).

I'm attaching a potential fix for this. Sorry I had no time for the UTs.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:3>

Django

unread,
Oct 11, 2021, 7:13:25 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------

Reporter: Thierry Bastian | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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):

* has_patch: 1 => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Oct 11, 2021, 9:06:30 AM10/11/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: assigned

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

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

* owner: nobody => Jordan Bae
* status: new => assigned


Comment:

I will check it!

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

Django

unread,
Oct 30, 2021, 2:26:42 PM10/30/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15037 PR]

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

Django

unread,
Nov 2, 2021, 3:29:48 AM11/2/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Nov 2, 2021, 11:47:48 AM11/2/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jordan Bae):

* needs_better_patch: 1 => 0


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

Django

unread,
Nov 2, 2021, 1:54:19 PM11/2/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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/33187#comment:9>

Django

unread,
Nov 2, 2021, 3:14:41 PM11/2/21
to django-...@googlegroups.com
#33187: Foreign key to a specific field is not handled in inspectdb
-------------------------------------+-------------------------------------
Reporter: Thierry Bastian | Owner: Jordan
| Bae
Type: Bug | Status: closed

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

Keywords: | 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):

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


Comment:

Fixed in
[https://github.com/django/django/commit/aaf9b558583d9bb75a0c9d53b135dc8c1b75b6a2
aaf9b558583d9bb75a0c9d53b135dc8c1b75b6a2].

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

Reply all
Reply to author
Forward
0 new messages