Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #18556 - Allowed RelatedManager.add() to execute 1 query where possible. #4319

Closed
wants to merge 1 commit into from

Conversation

timgraham
Copy link
Member


The ``add()`` method executes one query regardless of the number
of objects being added, (unless the objects have not yet been saved
to the database in which case that is done). In prior versions, it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put the opening parenthesis before "in which case" instead of directly after the comma.

@timgraham timgraham force-pushed the 18552-2 branch 3 times, most recently from 768fc00 to 4e1cc7f Compare March 28, 2015 12:53
@timgraham
Copy link
Member Author

@loic, tests are passing, but not sure the changes in GFK are entirely correct/sufficient. Some more tests might be needed. Could you check?

@@ -36,7 +36,7 @@ Related objects reference
In this example, the methods below will be available both on
``topping.pizza_set`` and on ``pizza.toppings``.

.. method:: add(obj1, [obj2, ...])
.. method:: add(obj1, [obj2, ..., bulk=False])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it bulk=True?

setattr(obj, self.object_id_field_name, self.pk_val)
obj.save()
if obj._state.adding or obj._state.db != db:
raise ValueError("%r instance isn't saved, but must be." % obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception message is different from that in related.py though the logic/intention surrounding it seems to be the same. Is this intentional?
(FWIW, I find the message in related.py to be clearer)

setattr(obj, self.object_id_field_name, self.pk_val)

if bulk:
ids = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but pks maybe?

@loic
Copy link
Member

loic commented Jul 28, 2015

Test failure seems unrelated. Left a couple of nitpick comments, otherwise PR looks great, I'm happy to merge it afterwards.

@loic
Copy link
Member

loic commented Jul 28, 2015

Merged in adc0c4f. Sorry I took so long to give a final review ;)

@loic loic closed this Jul 28, 2015
@timgraham timgraham deleted the 18552-2 branch July 28, 2015 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants