{"record":{"id":"b11cc388df749315","repo":"apache/superset","slug":"field-is-required","errorCode":null,"errorMessage":"Field is required","messagePattern":"Field is required","errorType":"validation","errorClass":"DatabaseRequiredFieldValidationError","httpStatus":422,"severity":"error","filePath":"superset/commands/database/create.py","lineNumber":62,"sourceCode":"from superset.exceptions import OAuth2RedirectError, SupersetErrorsException\nfrom superset.extensions import event_logger\nfrom superset.models.core import Database\nfrom superset.utils.decorators import on_error, transaction\n\nlogger = logging.getLogger(__name__)\nstats_logger = app.config[\"STATS_LOGGER\"]\n\n\nclass CreateDatabaseCommand(BaseCommand):\n    def __init__(self, data: dict[str, Any]):\n        self._properties = data.copy()\n\n    @transaction(on_error=partial(on_error, reraise=DatabaseCreateFailedError))\n    def run(self) -> Model:\n        self.validate()\n\n        if \"sqlalchemy_uri\" not in self._properties:\n            raise DatabaseRequiredFieldValidationError(\"sqlalchemy_uri\")\n\n        url = make_url_safe(self._properties[\"sqlalchemy_uri\"])\n        engine = url.get_backend_name()\n\n        try:\n            # Test connection before starting create transaction\n            TestConnectionDatabaseCommand(self._properties).run()\n        except OAuth2RedirectError:\n            # If we can't connect to the database due to an OAuth2 error we can still\n            # save the database. Later, the user can sync permissions when setting up\n            # data access rules.\n            return self._create_database()\n        except (\n            SupersetErrorsException,\n            SSHTunnelingNotEnabledError,\n            SSHTunnelDatabasePortError,\n            SSHTunnelHostKeyVerificationError,\n        ) as ex:","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/create.py#L44-L80","documentation":"DatabaseRequiredFieldValidationError raised with 'Field is required' semantics when the sqlalchemy_uri property is missing from the create payload. Two guards exist: validate() appends DatabaseRequiredFieldValidationError('sqlalchemy_uri') when self._properties.get('sqlalchemy_uri') is falsy, and run() re-checks 'sqlalchemy_uri' not in self._properties before making the URL. The message text 'Field is required' is the base ValidationError default for a missing field.","triggerScenarios":"POST /api/v1/database/ with a JSON body lacking sqlalchemy_uri (or with it null / empty string — run() then also fails make_url_safe or the key check).","commonSituations":"Client sends only database_name; a form or Terraform/Ansible module drops the field; typo like 'sqlalchemyUri' or 'uri' instead of sqlalchemy_uri; JSON body malformed so fields land nowhere.","solutions":["Include a well-formed sqlalchemy_uri, e.g. 'postgresql://user:pass@host:5432/db'.","Check for key-name typos and casing — the REST field is exactly sqlalchemy_uri.","If building the payload programmatically, assert the key exists before POSTing."],"exampleFix":"# before\nPOST /api/v1/database/\n{\"database_name\": \"mydb\"}  # missing URI\n\n# after\n{\"database_name\": \"mydb\", \"sqlalchemy_uri\": \"postgresql://user:pass@host:5432/db\"}","handlingStrategy":"validation","validationCode":"def valid_create_payload(data: dict) -> bool:\n    return bool(data.get(\"database_name\")) and bool(data.get(\"sqlalchemy_uri\"))","typeGuard":"def is_create_database_payload(data: dict) -> bool:\n    return (\n        isinstance(data, dict)\n        and isinstance(data.get(\"database_name\"), str)\n        and isinstance(data.get(\"sqlalchemy_uri\"), str)\n        and \"://\" in data[\"sqlalchemy_uri\"]\n    )","tryCatchPattern":null,"preventionTips":["Assert both database_name and sqlalchemy_uri are non-empty strings before POSTing.","Use the exact field names of the REST schema (sqlalchemy_uri, not uri/sqlalchemyUri).","Validate the payload against the database POST schema marshmallow exposes."],"tags":["database","validation","required-field","create","sqlalchemy-uri"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}