Django

Code

Ticket #7270 (closed: fixed)

Opened 2 years ago

Last modified 21 hours ago

selected_related() can not follow reverse relations of OneToOne.

Reported by: towjzhou@hotmail.com Assigned to: mtredinnick
Milestone: 1.2 Component: Database layer (models, ORM)
Version: SVN Keywords: select_related onetoone reverse performance
Cc: oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com, david, s.angel@twidi.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Here are my models:

# The base model
class User(models.Model):
    username = models.CharField()
    password = models.CharField()

# The model holds extra info to User
class UserProfile(models.Model):
    user  = models.OneToOneField(User)
    address = models.CharField()

# Then query the user with extra info:
    users = User.objects.select_related('userprofile')

Above code can't work, because select_related only accepts ForeignKey fields.

Attachments

django_select_related_onetoone_r7534.patch (2.2 kB) - added by towjzhou@hotmail.com on 05/21/08 22:39:00.
a dirty patch to fix this ticket.
django_select_related_onetoone_r7534.2.patch (2.4 kB) - added by towjzhou@hotmail.com on 05/28/08 04:05:42.
A updated patch to fix this ticket. This patch only work in select(fields...) mode, not effect on select()/select(depth=?) mode.
121_reverse_r7601.patch (9.6 kB) - added by gav on 06/09/08 20:39:39.
121_reverse_r7831.patch (21.1 kB) - added by gav on 07/07/08 16:36:50.
Updated patch again r7831, friendlier towards FK(unique=True)
121_reverse_r8985.patch (21.5 kB) - added by gav on 09/16/08 08:13:20.
121 reverse patch updated to r8985.
121_reverse_r10396.patch (21.2 kB) - added by bendavis78 on 04/05/09 11:23:44.
121_reverse_patch updated to 10396
django_select_related_onetoone_r10448.patch (6.9 kB) - added by aiev on 04/08/09 14:28:26.
adaptation to the r10448
django_select_related_onetoone_r10454.patch (22.4 kB) - added by bendavis78 on 04/08/09 20:26:35.
Updated to always use LEFT OUTER JOINs, added back tests
django_select_related_onetoone.patch (9.1 kB) - added by bendavis78 on 09/03/09 17:19:19.
patches against trunk, r11479
reverse_select_related.diff (11.5 kB) - added by Alex on 01/09/10 17:20:26.
12307-onetoone-null.patch (0.6 kB) - added by s.angel@twidi.com on 02/08/10 15:12:18.
http://code.djangoproject.com/ticket/7270#comment:67

Change History

05/21/08 01:26:37 changed by anonymous

  • needs_better_patch changed.
  • component changed from Uncategorized to Database wrapper.
  • needs_tests changed.
  • needs_docs changed.

05/21/08 22:39:00 changed by towjzhou@hotmail.com

  • attachment django_select_related_onetoone_r7534.patch added.

a dirty patch to fix this ticket.

05/24/08 14:08:58 changed by marc.boeker@gmail.com

thanks for the patch, but this also affects ForeignKeys? and results in a extraordinary large invalid sql query:)

05/28/08 04:05:42 changed by towjzhou@hotmail.com

  • attachment django_select_related_onetoone_r7534.2.patch added.

A updated patch to fix this ticket. This patch only work in select(fields...) mode, not effect on select()/select(depth=?) mode.

06/09/08 20:39:24 changed by gav

The newly attached patch is another approach to doing this, and shares some points with the original ticket creator. However, this patch also covers reverse caching, safely handles following all types of ForeignKeys? attached to OneToOneFields?, and includes unit tests and documentation.

06/09/08 20:39:39 changed by gav

  • attachment 121_reverse_r7601.patch added.

06/23/08 01:11:25 changed by gav

  • owner changed from nobody to gav.

07/07/08 16:36:50 changed by gav

  • attachment 121_reverse_r7831.patch added.

Updated patch again r7831, friendlier towards FK(unique=True)

08/07/08 08:49:36 changed by miracle2k

Should be in a 1.0 milestone?

08/07/08 15:21:04 changed by gav

  • milestone set to 1.0.

Some conversations I've had with core devs make me think so, so I'm updating the milestone appropriately.

08/07/08 15:47:18 changed by mtredinnick

This is kind of "1.0 maybe if we get time", which really means before the beta release next week. It'd be nice to have in and it's probably very close to right, but if we don't get it in, the world won't end either.

08/07/08 15:47:26 changed by mtredinnick

  • stage changed from Unreviewed to Accepted.

08/24/08 13:09:55 changed by mtredinnick

  • milestone changed from 1.0 to post-1.0.

Moving this to post-1.0, in line with my above comment. I know gav has done a lot of work on this (thanks for that, George!) and it would be nice to get it in, but I've just reread the patch and, although it looks correct, it does hit a lot of code that is used frequently and can hide subtle bugs. In the interests of stability (and feature freeze), it can wait,

09/16/08 07:59:02 changed by oyvind

  • cc set to oyvind.altvik@gmail.com.
  • keywords set to select_related onetoone reverse.

09/16/08 08:13:20 changed by gav

  • attachment 121_reverse_r8985.patch added.

121 reverse patch updated to r8985.

09/16/08 08:14:15 changed by gav

The newest uploaded patch brings this to r8985, but in every other way is the same as the previous patch.

09/17/08 06:28:00 changed by oyvind

  • has_patch set to 1.

Seems sound to me, and the tests pass.

10/01/08 13:47:30 changed by robin

How would I go about making the patch use LEFT JOIN (or LEFT OUTER JOIN) instead of INNER JOIN?

10/06/08 07:12:06 changed by gav

This patch automatically makes the LEFT JOIN for any FK relationships where null=True. You should not have to do anything beyond this.

10/07/08 23:31:28 changed by robin

Since this is a one-to-one relationship, the foreign key is also the primary key, so null is never true, hence LEFT JOIN will never occur unless forced somehow.

10/07/08 23:38:07 changed by mtredinnick

There's a bug in the patch, robin. Reverse one-to-one's always have to use an outer join, since there's no guarantee that the related object exists (they are all nullable relationships when followed in reverse). I'll fix this when I commit the change; I noticed it before and have a note about it. That will happen, soon.

10/07/08 23:39:17 changed by mtredinnick

(Oh, I should point out that it doesn't have to be an outer join if we're already filtering against that relation and didn't need an outer join the first time.)

11/12/08 10:26:52 changed by bhagany

  • cc changed from oyvind.altvik@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com.

12/20/08 10:36:05 changed by miracle2k

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com.

01/06/09 03:19:47 changed by gregoire

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr.

01/09/09 22:17:58 changed by andrewbadr

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com.

01/29/09 22:02:07 changed by Anossov

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com.

02/17/09 03:36:21 changed by kiriyama

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com.

02/19/09 14:09:45 changed by dbronner

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com.

02/25/09 13:51:44 changed by

  • milestone deleted.

Milestone post-1.0 deleted

02/28/09 21:14:17 changed by mtredinnick

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav.
  • owner changed from gav to mtredinnick.

Assigning to me so that it appears on my list of tickets to deal with. Will reassign back to gav if any insurmountable problem emerges, but I think this is pretty close to what we can use.

03/08/09 08:15:24 changed by Boo

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com.

03/10/09 09:49:36 changed by vbmendes

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com.

03/23/09 20:42:46 changed by mtredinnick

  • milestone set to 1.2.

03/24/09 23:55:50 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com.

04/02/09 10:46:14 changed by aiev

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com.
  • needs_better_patch set to 1.
  • needs_tests set to 1.

I use the svn version and when I apply the patch with command "patch -p0 -i ~/121_reverse_r8985.patch" ocurrence some errors because the merge dont work correctly.

But when I aplly the patch manually and debug some lines it work! :D

Why it has not yet been implemented in current version? :( Just curiosity

Thanks.

04/05/09 11:23:44 changed by bendavis78

  • attachment 121_reverse_r10396.patch added.

121_reverse_patch updated to 10396

04/05/09 11:24:51 changed by bendavis78

I've attached a version of the patch against r10396.

Also, I modified the self.join() call to set promote=True so that LEFT OUTER joins are always used -- although I'm not sure if that was all I needed to do, as I'm seeing a problem with the returned queryset when some of the joined values are null.

For example, let's say we have some User records that don't have associated UserProfile records. When we do:

>>> print User.objects.select_related('userprofile').query.as_sql()[0]
'SELECT `auth_user`.`id`, `myapp_userprofile`.`id`, FROM `auth_user` LEFT OUTER JOIN `myapp_userprofile` ON (`auth_user`.`id` = `myapps_userprofile`.`user_id`)'

... we get the correct SQL, and running this in dbshell returns the correct results, with the columns from UserProfile set to NULL.

However, when we try to output the queryset object, we get an empty list:

>>> q = User.objects.select_related('user_profile')
>>> q
[]
>>> 

Any ideas on why this is occurring?

Also, I've noticed some other problems that come up when we .values() or .only() on the query set, so I think this patch needs a little more refining before we can get it to work.

04/08/09 03:15:45 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, niktika@gmail.com.

04/08/09 03:16:41 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, niktika@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com.

04/08/09 14:28:26 changed by aiev

  • attachment django_select_related_onetoone_r10448.patch added.

adaptation to the r10448

04/08/09 14:36:10 changed by aiev

A updated patch, no bug like:

>>> q = User.objects.select_related('user_profile')
>>> q
[]
>>> 

But the problem persists when we .only() on the query set.

The .values() works fine, right?

04/08/09 20:22:53 changed by bendavis78

  • needs_better_patch deleted.

aiev, thanks. That seemed to fix the problem I was having :-) Although you left out the change I made in the last patch that forces the join to always be LEFT OUTER, as mtredinnick explained above. I've attached an updated patch.

04/08/09 20:26:35 changed by bendavis78

  • attachment django_select_related_onetoone_r10454.patch added.

Updated to always use LEFT OUTER JOINs, added back tests

04/08/09 20:26:49 changed by bendavis78

Oops, just realized the tests somehow didn't make it into that patch. Patch updated.

04/08/09 20:27:48 changed by bendavis78

  • needs_tests deleted.

04/13/09 22:46:33 changed by Glenn

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com.

Recursive select_related() (with no fields specified) doesn't seem to work yet.

04/13/09 23:45:45 changed by bendavis78

  • needs_better_patch set to 1.

05/27/09 12:10:35 changed by bendavis78

  • needs_better_patch deleted.
  • needs_tests set to 1.

Ok, I've updated the patch and fixed some code that was mysteriously duplicated, as well as fixed the tests that were written for the select_related change (they just needed init files).

I also believe I have the .values() query working with reverse one-to-one relationships, though I'd really like mtredinnick to take a look at the change since he's the one that wrote the original code for this. The change was fairly simple. In the setup_joins function in db/models/sql/query.py:

                     raise FieldError("Cannot resolve keyword %r into field. "
                             "Choices are: %s" % (name, ", ".join(names)))

-            if not allow_many and (m2m or not direct):
+            if not allow_many and m2m:
                 for alias in joins:
                     self.unref_alias(alias)
                 raise MultiJoin(pos + 1)

Looking at the original code, I'm not sure why "indirect" fields were not allowed if they weren't many-to-many relationships. This is basically what was keeping the reverse one-to-one lookups from working. I'm not 100% sure of the consequences of this change, but all model tests seemed to pass with this change.

@mtredinnick: thoughts?

We still need a test for this particular change, so I'm leaving "Needs tests" checked for now.

08/21/09 09:49:39 changed by IonelMaries

  • owner changed from mtredinnick to IonelMaries.
  • status changed from new to assigned.

08/21/09 09:50:12 changed by IonelMaries

  • owner changed from IonelMaries to mtredinnick.
  • status changed from assigned to new.

08/21/09 09:52:29 changed by IonelMaries

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com.

08/24/09 15:35:49 changed by garrison

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison.

08/25/09 11:09:29 changed by garrison

Why not make this (following reverse relationships as well as forward ones) the default behavior if select_related() is given no arguments?

08/25/09 12:16:52 changed by bendavis78

I'm honestly not sure why the attached patch hasn't made it in -- I've been using it in my production environments and haven't had any problems. I was waiting on some feedback from mtredinnick, as to what the "if not allow_many and (m2m or not direct)" was for, but I'm not sure if he's following this ...

08/25/09 16:39:25 changed by SmileyChris

It's not ready for checkin, because it's missing the test (you marked it as such). After the test is added, feel free to bring it up in the dev google group.

08/28/09 03:03:12 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com.

09/03/09 17:19:19 changed by bendavis78

  • attachment django_select_related_onetoone.patch added.

patches against trunk, r11479

09/03/09 17:21:20 changed by bendavis78

  • needs_tests deleted.

Ok, I've update the patch for the r11479, and have included a basic test (it's my first time for this, so please advise if it needs to be better).

09/08/09 19:11:56 changed by dchristian

Patch fails when the relationship is held on a base class.

class A(models.Model):

pass

class B(A):

pass

class C(models.Model):

a_ref = models.OneToOneField?('A', related_name='c_list')

B.objects.select_related('c_list')

fails. Reproducing from memory as I am not using this patch now. In any case it's pretty clear that the patch ignores base classes.

09/10/09 17:28:37 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com.

(follow-up: ↓ 54 ) 09/11/09 10:15:40 changed by bendavis78

@dchristian: I'm a bit confused by your use case there, as I don't see how that particular setup would be used in a real-world situation. That is, I'm having trouble seeing a situation where I would have a one-to-one referencing a base model. If you could provide a more real-world example that would help.

(in reply to: ↑ 53 ) 09/17/09 12:15:22 changed by dchristian

We have a generic Content type, and a Article type that is a more specific type of content. Content is linked to by other sub-objects, one of which is a OneToOne? but is kept in a different app to keep things separated nicely.

But in any case, the point is that this patch, if applied, will result in tracebacks when used in that situation, so I wouldn't recommend approving it until the situation is at least handled in some way that doesn't crash.

09/24/09 16:31:22 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com.

10/08/09 15:17:43 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com.

10/16/09 13:21:15 changed by oldium

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz.

11/04/09 02:47:13 changed by drakkan <nicola.murino@gmail.com>

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com.

11/09/09 08:12:16 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org.

11/19/09 06:03:46 changed by daemianmack

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com.

12/03/09 09:12:38 changed by Harm Geerts <hgeerts@osso.nl>

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl.

12/17/09 12:05:22 changed by powderflask

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com.

12/17/09 12:22:15 changed by anonymous

  • keywords changed from select_related onetoone reverse to select_related onetoone reverse performance.

12/21/09 03:30:30 changed by david

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com, david.

01/09/10 17:20:26 changed by Alex

  • attachment reverse_select_related.diff added.

01/09/10 22:15:16 changed by Alex

This new version passes all tests (both the ones it introduces and the existing ones), I didn't implement the reverse-fkey support because it seemed a bit hacky to me. Any other test cases would be great.

01/27/10 07:30:30 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [12307]) Fixed #7270 -- Added the ability to follow reverse OneToOneFields? in select_related(). Thanks to George Vilches, Ben Davis, and Alex Gaynor for their work on various stages of this patch.

02/08/10 15:09:56 changed by s.angel@twidi.com

  • status changed from closed to reopened.
  • resolution deleted.

The commit [12307] has a bug. If i use select_related with a OneToOneField? which can be null, if for the FIRST object, this relation is null, then it's give me an error

A path is joined

02/08/10 15:12:18 changed by s.angel@twidi.com

  • attachment 12307-onetoone-null.patch added.

02/08/10 15:12:50 changed by anonymous

  • cc changed from oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com, david to oyvind.altvik@gmail.com, brent.hagany@gmail.com, elsdoerfer@gmail.com, gregoire@audacy.fr, andrewbadr.etc@gmail.com, anossov@gmail.com, kimavr@gmail.com, dbronner@google.com, gav, Boobsd@gmail.com, vbmendes@gmail.com, bendavis78@gmail.com, aiev.an.tks@gmail.com, nikitka@gmail.com, glennfmaynard@gmail.com, ionel.mc@gmail.com, garrison, dexterbt1@yahoo.com, jdunck@gmail.com, kmike84@gmail.com, vinilios@gmail.com, oldium.pro@seznam.cz, nicola.murino@gmail.com, mike@yumatov.org, daemianmack@gmail.com, hgeerts@osso.nl, powderflask@gmail.com, david, s.angel@twidi.com.

02/08/10 16:49:51 changed by Alex

  • status changed from reopened to closed.
  • resolution set to fixed.

The original issue here was fixed, please open a new bug for the new issue.


Add/Change #7270 (selected_related() can not follow reverse relations of OneToOne.)




Change Properties
Action