← Back to team overview

maas-devel team mailing list archive

Re: Unique Space Names

 

On Wed, Nov 4, 2015 at 4:07 AM, John A Meinel <john.meinel@xxxxxxxxxxxxx>
wrote:
>
> One thing I noticed with my recent explore into the MAAS Networking code
is that the name field of spaces is not flagged as Unique. This seems a bit
surprising as it is only via the name that the user is specifying what
space they want their machines to be in.
>
> Am I missing something about the layout?

   Thanks for noticing this. This may be something we want to address
before MAAS 1.9 releases.

   I'm guessing it was done this way in order to support NULL names, in
order to be consistent with fabrics and subnets. That is, subnets and
fabrics without a specific name (which would be the case if MAAS observed
the objects' existance) could be addressed by specifying subnet-<id> or
fabric-<id>. The same was done for spaces (though this is a bit confusing,
since the concept of a space is more likely to be user-defined than
auto-discovered... although it's possible that we could one day discover
spaces - such as by looking at router/switch ACLs, or by trial and error -
and thus need nice machine-defined names).

   I think the cause of this is captured in an Q&A I found on Stack
Overflow[1], which states:

"""
Django has not considered NULL to be equal to NULL for the purpose of
uniqueness checks since ticket #9039 was fixed, see:

http://code.djangoproject.com/ticket/9039

The issue here is that the normalized "blank" value for a form CharField is
an empty string, not None. So if you leave the field blank, you get an
empty string, not NULL, stored in the DB. Empty strings are equal to empty
strings for uniqueness checks, under both Django and database rules.

"""

   That is, we probably made it unique=False to work around this quirk in
Django, when we should have done it a slightly different way, such as the
one captured in the answer. (what we really wanted to say was, names must
be unique, unless they're NULL, in which case they will be represented by
ID instead.)

Regards,
Mike

[1]: http://stackoverflow.com/a/1400046/77939

Follow ups

References