amy: Bulk import workflow encounters IntegrityError when saving an organization

Currently, we allow organizations with the domain that contains the www subdomain. For eg: Google can exist as www.google.com as well as google.com, leading to IntegrityError while saving the first while the second exists.

Shouldn’t we enforce one URL pattern and trim/add www to the domain field when saving an organization?

Testcase:

In [5]: Organization.objects.create(fullname='Google', domain='google.com')
Out[5]: <Organization: google.com>

In [6]: Organization.objects.create(fullname='Google', domain='www.google.com')
---------------------------------------------------------------------------
IntegrityError                            Traceback (most recent call last)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 27 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I cannot check if a similar org exists, before saving a new one

Organization.objects.filter(Q(fullname=fullname) | Q(domain=domain)).first() # returns one record or None

Does it solve the issue? If no, why?

I propose we exclusively use the domain field to uniquely identify organizations after we enforce a strict domain convention (no www subdomain). tld package can help us here.

-1 - I’ve seen a number of places that serve content only with www. subdomain… Essentially, www.domain.tld != domain.tld.