Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
bulk_create and ManyToManyField: bug ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael  
View profile  
 More options May 7 2012, 3:53 pm
From: Michael <michael.palumb...@gmail.com>
Date: Mon, 7 May 2012 12:53:29 -0700 (PDT)
Local: Mon, May 7 2012 3:53 pm
Subject: bulk_create and ManyToManyField: bug ?

Hi,

I am using bulk_create on a ManyToMany relationship and I think there is a
bug.
Here is the code:
class Company(models.Model):
    url = models.URLField(unique=True)

class Website(models.Model):
    url = models.URLField(unique=True)
    companies = models.ManyToManyField(Company, null=True, blank=True)

list_companies = [Company(url='...'), Company(url='...')]
w.companies.bulk_create(list_companies)
-> [< Company:  Company object>, < Company:  Company object>]   #The 2
Company objects are created

w.companies.all()
-> []   # But the relationship is broken

The 2 companies are created but I cannot access to them through my
many-to-many relationship.
I looked at the database and yes I can find the 2 companies in the company
table but no rows in the website_company table.

What do you think ? Do you have the same behavior ?
Lemme know if I do it wrong.

Thanks
Michael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anssi Kääriäinen  
View profile  
 More options May 7 2012, 4:04 pm
From: Anssi Kääriäinen <anssi.kaariai...@thl.fi>
Date: Mon, 7 May 2012 13:04:31 -0700 (PDT)
Local: Mon, May 7 2012 4:04 pm
Subject: Re: bulk_create and ManyToManyField: bug ?
On May 7, 10:53 pm, Michael <michael.palumb...@gmail.com> wrote:

Hmmh, I think you have found an oversight. Please open a ticket in
Trac. It is possible the fix is going to be just to disallow use of
bulk_create through relations, as fixing this properly is going to be
hard (to create the relation you need the PK of the objects created,
and bulk_create doesn't provide the PK if it comes from a
sequence...). Or, maybe just document that no, the relations are not
created for you. For reverse foreign key this could be fixed
however...

 - Anssi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael  
View profile  
 More options May 7 2012, 4:46 pm
From: Michael <michael.palumb...@gmail.com>
Date: Mon, 7 May 2012 13:46:10 -0700 (PDT)
Local: Mon, May 7 2012 4:46 pm
Subject: Re: bulk_create and ManyToManyField: bug ?

ok, I created it:  https://code.djangoproject.com/ticket/18285

Le lundi 7 mai 2012 22:04:31 UTC+2, Anssi Kääriäinen a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael  
View profile  
 More options May 7 2012, 5:21 pm
From: Michael <michael.palumb...@gmail.com>
Date: Mon, 7 May 2012 14:21:28 -0700 (PDT)
Local: Mon, May 7 2012 5:21 pm
Subject: Re: bulk_create and ManyToManyField: bug ?

So the only option I have for now is to iterate through each object and
call create right ?

list_companies = [Company(url='...'), Company(url='...')]
for c in list_companies:
    w.companies.create(c)

Best,
Michael

Le lundi 7 mai 2012 22:46:10 UTC+2, Michael a écrit :


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »