﻿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
14944	Saving a model which refers to unexistent models does not spit any errors	ferran	nobody	"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.
}}}"		closed	Database layer (models, ORM)	1.2		invalid			Unreviewed	0	0	0	0	0	0
