{"action":"opened","issue":{"url":"https://api.github.com/repos/karanlyons/django-save-the-change/issues/10","labels_url":"https://api.github.com/repos/karanlyons/django-save-the-change/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/karanlyons/django-save-the-change/issues/10/comments","events_url":"https://api.github.com/repos/karanlyons/django-save-the-change/issues/10/events","html_url":"https://github.com/karanlyons/django-save-the-change/issues/10","id":57028778,"number":10,"title":"Multiple DB hits on following m2m relations","user":{"login":"lyudmildrx","id":4178825,"avatar_url":"https://avatars.githubusercontent.com/u/4178825?v=3","gravatar_id":"","url":"https://api.github.com/users/lyudmildrx","html_url":"https://github.com/lyudmildrx","followers_url":"https://api.github.com/users/lyudmildrx/followers","following_url":"https://api.github.com/users/lyudmildrx/following{/other_user}","gists_url":"https://api.github.com/users/lyudmildrx/gists{/gist_id}","starred_url":"https://api.github.com/users/lyudmildrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyudmildrx/subscriptions","organizations_url":"https://api.github.com/users/lyudmildrx/orgs","repos_url":"https://api.github.com/users/lyudmildrx/repos","events_url":"https://api.github.com/users/lyudmildrx/events{/privacy}","received_events_url":"https://api.github.com/users/lyudmildrx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-09T13:14:31Z","updated_at":"2015-02-09T13:14:31Z","closed_at":null,"body":"Hello,\r\n\r\nWant to report an issue I saw with a different implementation of 'save changed only'. As I really wanted to just replace the faulty implementation with this repo, I reproduced the same ussue with django-save-the-change. \r\n\r\nExample of the issue:\r\n\r\n'''python\r\nfrom django.db import models\r\nfrom django.contrib.auth.models import User\r\n\r\nfrom save_the_change.mixins import SaveTheChange\r\n\r\nclass TodoList(models.Model):\r\n    title = models.TextField()\r\n    description = models.TextField()\r\n    owner = models.ForeignKey(User, related_name='owned_set')\r\n    shared_with = models.ManyToManyField(User, related_name='shared_lists')\r\n\r\n\r\nclass TodoItem(SaveTheChange, models.Model):\r\n    \"\"\" \r\n    Basic todo item\r\n\r\n    It has a `title`, an `order` and can be marked as `done`\r\n    \"\"\"\r\n    todolist = models.ForeignKey(TodoList)\r\n    title = models.TextField()\r\n    order = models.IntegerField(blank=True, null=True)\r\n    done = models.BooleanField(default=False)\r\n'''\r\n>>> from django.db import connection\r\n>>> len(connection.queries)\r\n0\r\n>>> from todo.models import TodoItem, TodoList\r\n>>> from django.db import connection\r\n>>> q = TodoList.objects.all()[0]\r\n>>> len(connection.queries)\r\n1\r\n>>> a = q.todoitem_set.all()\r\n>>> len(connection.queries)\r\n1\r\n>>> z = list(a)\r\n>>> len(connection.queries)\r\n17\r\n>>> connection.queries[-1]['sql']  # Last 16 queries are the same\r\nu'SELECT \"todo_todolist\".\"id\", \"todo_todolist\".\"title\", \"todo_todolist\".\"description\", \"todo_todolist\".\"owner_id\" FROM \"todo_todolist\" WHERE \"todo_todolist\".\"id\" = 1 '\r\n\r\nFor the other implementation, 'the cause' was a call to hasattr(self, name) in Model.__setattr__. Cause == removing the hasattr call removed the issue too. On first read, I would say 'the cause' here is different."}}