sahana / eden

Sahana Eden is an Open Source Humanitarian Platform which can be used to provide solutions for Disaster Management, Development, and Environmental Management sectors.. Please sign CLA when submitting pull requests: http://bit.ly/SSF-eCLA
http://eden.sahanafoundation.org
Other
387 stars 559 forks source link

Renaming Organization Type to a name which already exists crashes with UniqueViolation error #1559

Closed trendspotter closed 4 years ago

trendspotter commented 4 years ago

Steps to reproduce (assumes default template with demo data):

  1. Go to Organizations ->Organization types -> Create
  2. Create a type filling in required name field as "NGO" (or any other existing value)
  3. Click on Save and observe error
    Traceback (most recent call last):
    File "/srv/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
    File "/srv/web2py/applications/eden/controllers/org.py", line 511, in <module>
    File "/srv/web2py/gluon/globals.py", line 429, in <lambda>
    self._caller = lambda f: f()
    File "/srv/web2py/applications/eden/controllers/org.py", line 181, in organisation_type
    return s3_rest_controller()
    File "/srv/web2py/applications/eden/models/00_utils.py", line 245, in s3_rest_controller
    output = r(**attr)
    File "/srv/web2py/applications/eden/modules/s3/s3rest.py", line 691, in __call__
    output = self.resource.crud(self, **attr)
    File "/srv/web2py/applications/eden/modules/s3/s3rest.py", line 1775, in __call__
    output = self.apply_method(r, **attr)
    File "/srv/web2py/applications/eden/modules/s3/s3crud.py", line 113, in apply_method
    output = self.select(r, **attr)
    File "/srv/web2py/applications/eden/modules/s3/s3crud.py", line 1280, in select
    form = self.create(r, **attr).get("form", None)
    File "/srv/web2py/applications/eden/modules/s3/s3crud.py", line 387, in create
    output["form"] = self.sqlform(request = request,
    File "/srv/web2py/applications/eden/modules/s3/s3forms.py", line 467, in __call__
    success, error = self.process(form,
    File "/srv/web2py/applications/eden/modules/s3/s3forms.py", line 668, in process
    if form.accepts(vars,
    File "/srv/web2py/gluon/sqlhtml.py", line 1989, in accepts
    self.vars.id = self.table.insert(**fields)
    File "/srv/web2py/gluon/packages/dal/pydal/objects.py", line 762, in insert
    ret = self._db._adapter.insert(self, row.op_values())
    File "/srv/web2py/gluon/packages/dal/pydal/adapters/base.py", line 487, in insert
    raise e
    File "/srv/web2py/gluon/packages/dal/pydal/adapters/base.py", line 482, in insert
    self.execute(query)
    File "/srv/web2py/gluon/packages/dal/pydal/adapters/__init__.py", line 67, in wrap
    return f(*args, **kwargs)
    File "/srv/web2py/gluon/packages/dal/pydal/adapters/base.py", line 413, in execute
    rv = self.cursor.execute(command, *args[1:], **kwargs)
    psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "org_organisation_type_name_key"
    DETAIL:  Key (name)=(NGO) already exists.