fix(delegated): tenant-template membership write failed (Edm.DateTime out of range)

AddTenantToTemplate returned 500 on the first add: the membership-row write
threw because TenantTemplateEntity.CreatedDate was left at default(DateTime)
(0001-01-01), which is below Azure Table Storage's Edm.DateTime minimum (1601).
The meta row wrote fine only because Create stamps CreatedDate=UtcNow.

Make CreatedDate nullable so membership rows omit it (null is valid); meta rows
still carry it. Read-back maps null -> default. Confirmed via storage: the
affected partition had only the meta row, no membership row.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Oliver Kieselbach
2026-06-29 18:53:39 +02:00
parent 3d6933c3f4
commit 3e827fbb92
2 changed files with 7 additions and 3 deletions
@@ -828,7 +828,7 @@ namespace AutopilotMonitor.Functions.DataAccess.TableStorage
{
template.Name = entity.Name;
template.CreatedBy = entity.CreatedBy;
template.CreatedAt = entity.CreatedDate;
template.CreatedAt = entity.CreatedDate ?? default;
return true;
}
@@ -414,8 +414,12 @@ public class TenantTemplateEntity : ITableEntity
/// <summary>UPN of the GlobalAdmin who created the template (meta row only).</summary>
public string CreatedBy { get; set; } = string.Empty;
/// <summary>When the template was created (meta row only).</summary>
public DateTime CreatedDate { get; set; }
/// <summary>
/// When the template was created (meta row only). NULLABLE on purpose: membership rows leave it unset, and
/// Azure Table Storage rejects a default(DateTime) (0001-01-01) — below the Edm.DateTime minimum of 1601 —
/// which would make every membership-row write throw. A null DateTime? is simply omitted (valid).
/// </summary>
public DateTime? CreatedDate { get; set; }
/// <summary>The managed tenant ID (lowercase) — denormalized copy of RowKey on membership rows; empty on meta.</summary>
public string TenantId { get; set; } = string.Empty;