{"record":{"id":"b576624582f4ee3a","repo":"getredash/redash","slug":"error-updating-record","errorCode":null,"errorMessage":"Error updating record","messagePattern":"Error updating record","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"redash/handlers/users.py","lineNumber":263,"sourceCode":"        try:\n            self.update_model(user, params)\n            models.db.session.commit()\n\n            if needs_to_verify_email:\n                send_verify_email(user, self.current_org)\n\n            # The user has updated their email or password. This should invalidate all _other_ sessions,\n            # forcing them to log in again. Since we don't want to force _this_ session to have to go\n            # through login again, we call `login_user` in order to update the session with the new identity details.\n            if current_user.id == user.id:\n                login_user(user, remember=True)\n        except IntegrityError as e:\n            if \"email\" in str(e):\n                message = \"Email already taken.\"\n            else:\n                message = \"Error updating record\"\n\n            abort(400, message=message)\n\n        self.record_event(\n            {\n                \"action\": \"edit\",\n                \"object_id\": user.id,\n                \"object_type\": \"user\",\n                \"updated_fields\": list(params.keys()),\n            }\n        )\n\n        return user.to_dict(with_api_key=is_admin_or_owner(user_id))\n\n    @require_admin\n    def delete(self, user_id):\n        user = models.User.get_by_id_and_org(user_id, self.current_org)\n        # admin cannot delete self; current user is an admin (`@require_admin`)\n        # so just check user id\n        if user.id == current_user.id:","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/handlers/users.py#L245-L281","documentation":"A catch-all for IntegrityError raised while updating a user row when the error text does not mention \"email\". The database rejected the write because some other constraint (non-null, unique, FK, length) was violated by the submitted fields, and the handler surfaces it as HTTP 400 with a generic message.","triggerScenarios":"POST /api/users/<id> with fields that violate a column constraint other than the email unique constraint — e.g. a null/empty required field, an over-length value, or a foreign key to a nonexistent row (depending on schema version).","commonSituations":"Schema drift after a Redash upgrade added constraints (migrations not applied); clients sending nulls or empty strings for required columns; legacy scripts posting fields that newer versions constrain.","solutions":["Inspect the database server logs or enable SQLAlchemy echo to see the underlying IntegrityError cause","Validate all submitted fields (non-empty required values, sane lengths) before the request","Run the latest migrations (bin/run ./manage.py database upgrade) so schema and code match","Reproduce with a minimal payload to isolate which field triggers the constraint"],"exampleFix":"// before\n{\"name\": null}  // 400 Error updating record\n// after\n{\"name\": \"Jane Doe\"}","handlingStrategy":"validation","validationCode":"for field in (\"name\",):\n    v = payload.get(field)\n    assert v is not None and str(v).strip() != \"\", f\"{field} required\"\n    assert len(str(v)) <= 255, f\"{field} too long\"","typeGuard":null,"tryCatchPattern":"resp = requests.post(url, json=payload, headers=hdrs)\nif resp.status_code == 400 and resp.json().get(\"message\") == \"Error updating record\":\n    logger.error(\"IntegrityError updating user %s: %s\", uid, payload)  # then check DB logs","preventionTips":["Keep schema migrations current after upgrades","Log the exact payload when this generic 400 appears so the offending field can be found","Pre-validate required and length-constrained fields client-side"],"tags":["redash","integrity-error","http-400","database-constraint","users"],"backgroundTag":"database-constraint-violation","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}