﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16865	get_or_create defaults to _for_write even when it's just reading	Rick van Hattem <Rick.van.Hattem@…>	nobody	"First a little background information. I am currently using an asynchronous master slave(s) setup which requires me to pin a request to the master as soon as Django does any writes.

This results in all code reading from the slaves when possible, and switching to the master as soon as data is written.

The problem comes with the `get_or_create` method. Most of the code that uses `get_or_create` expects to get a result and uses the `create` as a fallback if it doesn't exist. The result of this is that (atleast in all the cases where we use `get_or_create`), the `get_or_create` method is 99% reads and only a tiny bit of writes. With the current code however, Django defaults to using the write database as soon as `get_or_create` is called before ever executing an insert.

The link to the line that is causing this:
https://code.djangoproject.com/browser/django/trunk/django/db/models/query.py#L407

Was this done by design? If so, please explain the reasoning behind it.
Otherwise I would classify this as a bug and in that case it would be a good idea to move the `self._for_write = True` line to the `except self.model.DoesNotExist:` block where the actual writes happen."	Bug	closed	Database layer (models, ORM)	1.3	Normal	wontfix		v.oostveen@…	Accepted	1	0	0	0	1	0
