#14944: Saving a model which refers to unexistent models does not spit any errors ------------------------------------------+--------------------------------- Reporter: ferran | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.2 Keywords: | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- I had these models:
{{{ class IPv4(models.Model): addr = models.IPAddressField( unique=True, primary_key=True ) def __unicode__(self): return self.addr class Hostname(models.Model): host = models.CharField( max_length=200, unique=True, primary_key=True, ) def __unicode__(self): return self.host class NameServer(models.Model): host = models.ForeignKey(Hostname, related_name="hostname") ip = models.ForeignKey(IPv4, related_name="ip address") handle = GenericRelation(Handle, null=True) def __unicode__(self): return "%s (%s)" % (self.host, self.ip) class Meta: unique_together = ('host', 'ip') }}} If i try to add a NameServer with non-saved models, it does not fail until it searches for objects: {{{ >>> ns = NameServer(host=Hostname(host='tetuan.fompi.net'), ip=IPv4(addr='87.216.178.18')) >>> ns.save() >>> Hostname.objects.all() [<Hostname: seie.fompi.net>, <Hostname: uno.uno.uno>, <Hostname: dos.dos.dos>] >>> j.objects.all() Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 211, in __get__ raise AttributeError("Manager isn't accessible via %s instances" % type.__name__) AttributeError: Manager isn't accessible via NameServer instances >>> NameServer.objects.all() Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 71, in __repr__ return repr(data) File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 344, in __repr__ u = unicode(self) File "domains/models.py", line 114, in __unicode__ return "%s (%s)" % (self.host, self.ip) File "/usr/lib/python2.7/site- packages/django/db/models/fields/related.py", line 302, in __get__ rel_obj = QuerySet(self.field.rel.to).using(db).get(**params) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 341, in get % self.model._meta.object_name) DoesNotExist: Hostname matching query does not exist. }}} -- Ticket URL: <http://code.djangoproject.com/ticket/14944> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.