elsa-workflows/elsa-core · error · InvalidOperationException

SQLite identifier ' ' is not valid for physicalization.

Error message

SQLite identifier '{identifier}' is not valid for physicalization.

What it means

Quote validates every SQL identifier (table names, index names, columns) used in generated SQLite DDL against the regex ^[A-Za-z_][A-Za-z0-9_]*$. Identifiers containing dots, dashes, spaces, leading digits, or non-ASCII characters are rejected so the planner never emits unsafe or invalid quoted identifiers.

Solutions

  1. Rename the offending identifier to match ^[A-Za-z_][A-Za-z0-9_]*$ (letters, digits, underscores, not starting with a digit).
  2. Set policy.PhysicalName to a sanitized, regex-compliant physical name distinct from the logical storage unit name.
  3. Strip or replace invalid characters (e.g. dashes to underscores) before building the policy.

Example fix

// before
policy.PhysicalName = "workflow-instances";
// after
policy.PhysicalName = "workflow_instances";
Defensive patterns

Strategy: validation

Validate before calling

static readonly Regex Ident = new("^[A-Za-z_][A-Za-z0-9_]*$");
if (!Ident.IsMatch(policy.PhysicalName ?? policy.StorageUnit))
    throw new ArgumentException("Physical name must match ^[A-Za-z_][A-Za-z0-9_]*$.");

Try / catch

try { plan = planner.Plan(schema, policy); }
catch (InvalidOperationException ex) when (ex.Message.Contains("is not valid for physicalization")) { policy.PhysicalName = Sanitize(name); /* retry */ }

Prevention

When it happens

Trigger: Setting StoragePhysicalizationPolicy.PhysicalName to a value with invalid characters (e.g. workflow-instances, 9instances, dbo.WorkflowInstances) or declaring a schema storage unit/field/index whose name fails the regex, which then flows into tableName, fieldColumns, indexName, or indexColumns quoting.

Common situations: Copying logical names from other databases that allow dots or dashes; prefixing table names with digits; using hyphenated index names from configuration files.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/0b86e65f78ee0be4. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Persistence.VNext.Sqlite/Physicalization/SqlitePhysicalizationPlanner.cs:54

        foreach (var index in policy.Indexes)
        {
            var indexName = Quote(index.Name);
            var indexColumns = string.Join(", ", index.Fields.Select(field => Quote(field)));
            var unique = index.IsUnique ? "UNIQUE " : string.Empty;
            operations.Add(new(
                "CreateIndex",
                $"Create SQLite index {indexName} on {tableName}.",
                $"CREATE {unique}INDEX IF NOT EXISTS {indexName} ON {tableName} ({indexColumns});"));
        }

        return new PhysicalizationPlan("SQLite", policy, operations);
    }

    private static string Quote(string identifier)
    {
        if (!IdentifierRegex().IsMatch(identifier))
            throw new InvalidOperationException($"SQLite identifier '{identifier}' is not valid for physicalization.");

        return $"\"{identifier}\"";
    }

    [GeneratedRegex("^[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.Compiled)]
    private static partial Regex IdentifierRegex();
}

View on GitHub (pinned to fe9217bdfa)