Skip to content

Unicron fix one more bug#5035

Closed
lukaszgryglicki wants to merge 3 commits into
devfrom
unicron-fix-one-more-bug
Closed

Unicron fix one more bug#5035
lukaszgryglicki wants to merge 3 commits into
devfrom
unicron-fix-one-more-bug

Conversation

@lukaszgryglicki
Copy link
Copy Markdown
Member

Followup after switchover - safe to postpone to next week.

Copilot AI review requested due to automatic review settings May 7, 2026 14:27
@lukaszgryglicki lukaszgryglicki self-assigned this May 7, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d8168497-f8b0-4ca3-89fd-655d522a9265

📥 Commits

Reviewing files that changed from the base of the PR and between a9a417f and 368062b.

📒 Files selected for processing (1)
  • cla-backend-legacy/internal/api/github_oauth.go

Walkthrough

This PR stops converting DynamoDB items through intermediate map[string]any. GitHub OAuth user flows and legacy project Post/Put handlers now capture, mutate, and persist map[string]types.AttributeValue directly, then convert persisted items to interface maps only for API responses while preserving legacy numeric fields.

Changes

DynamoDB Native Persistence Pattern

Layer / File(s) Summary
AttributeValue Fetch and Assignment
cla-backend-legacy/internal/api/github_oauth.go, cla-backend-legacy/internal/api/handlers.go
Query results are now captured as raw map[string]types.AttributeValue instead of converting to map[string]any for GitHub user lookups (primary and fallback) and project creation.
AttributeValue Mutation and Persistence
cla-backend-legacy/internal/api/github_oauth.go, cla-backend-legacy/internal/api/handlers.go
Existing GitHub users and projects are patched or created in-place by writing types.AttributeValue fields (names, emails, github_id, project fields, timestamps) and persisted via PutItem without intermediate interface-map conversions.
Response Normalization
cla-backend-legacy/internal/api/github_oauth.go, cla-backend-legacy/internal/api/handlers.go
API responses convert the persisted AttributeValue item to map[string]any via store.ItemToInterfaceMap and explicitly restore legacy numeric shapes (e.g., user_github_id as int64) before returning.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Unicron fix one more bug' is vague and non-descriptive, using generic language that does not convey meaningful information about the specific technical changes in the changeset. Revise the title to specifically describe the main change, such as 'Preserve DynamoDB AttributeValue types in GitHub OAuth and project handlers' or 'Fix type-coercion bug in DynamoDB item conversions'.
Description check ❓ Inconclusive The description 'Followup after switchover - safe to postpone to next week' is vague and does not explain what actual changes are being made or why they are necessary. Provide a more detailed description explaining the bug being fixed, such as how the type-coercion parity issue affects DynamoDB conversions and what changes address it.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch unicron-fix-one-more-bug

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.1)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DynamoDB attribute-type coercion introduced by store.InterfaceMapToItem (via isNumericString) by avoiding JSON-style map round-trips in a couple of legacy API flows, ensuring digit-only string fields remain DynamoDB S (string) attributes.

Changes:

  • Build DynamoDB map[string]types.AttributeValue items directly when creating/updating /v1/project records to prevent digit-only project_name values from being stored as N.
  • Update GitHub OAuth “get or create user” flow to patch/persist raw DynamoDB AttributeValue maps, avoiding unintended SN coercion.
  • Preserve pre-cutover API response shape for user_github_id (return a JSON number) while still storing it as DynamoDB N.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cla-backend-legacy/internal/api/handlers.go Creates/updates Project items using raw DynamoDB AttributeValue maps to prevent numeric-string coercion.
cla-backend-legacy/internal/api/github_oauth.go Updates user create/update during GitHub OAuth using raw AttributeValue maps and maintains legacy user_github_id response shape.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
cla-backend-legacy/internal/api/github_oauth.go (2)

306-319: 💤 Low value

Minor inconsistency in user_github_username handling.

In the update path (line 273-275), user_github_username is only set if githubLogin != "", preserving existing values. Here in the create path, it's always set (line 312), potentially storing an empty string. While this is unlikely in practice (a valid GitHub user should have a login), consider applying the same guard for consistency:

-		"user_github_username": &types.AttributeValueMemberS{Value: githubLogin},
 	}
+	if githubLogin != "" {
+		itemAV["user_github_username"] = &types.AttributeValueMemberS{Value: githubLogin}
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cla-backend-legacy/internal/api/github_oauth.go` around lines 306 - 319, The
create-path always sets itemAV["user_github_username"] to githubLogin which can
store an empty string; mirror the update-path behavior by only adding the
"user_github_username" entry to the itemAV map when githubLogin != "" (same
guard used in the update branch) so existing/empty values aren't
persisted—modify the create branch where itemAV is constructed to conditionally
add the "user_github_username" key based on githubLogin.

282-286: 💤 Low value

Unreachable branch: emails are already validated non-empty.

The else branch that deletes user_emails is unreachable because lines 228-230 already return an error if len(emails) < 1. While this defensive code isn't harmful, it could be removed for clarity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cla-backend-legacy/internal/api/github_oauth.go` around lines 282 - 286,
Remove the unreachable else block that deletes "user_emails": since emails is
already validated to be non-empty earlier, simply set userAV["user_emails"] =
&types.AttributeValueMemberSS{Value: emails} (or assign unconditionally) and
delete the conditional else branch that calls delete(userAV, "user_emails");
this cleans up dead code around the userAV, emails and
types.AttributeValueMemberSS usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cla-backend-legacy/internal/api/github_oauth.go`:
- Around line 306-319: The create-path always sets
itemAV["user_github_username"] to githubLogin which can store an empty string;
mirror the update-path behavior by only adding the "user_github_username" entry
to the itemAV map when githubLogin != "" (same guard used in the update branch)
so existing/empty values aren't persisted—modify the create branch where itemAV
is constructed to conditionally add the "user_github_username" key based on
githubLogin.
- Around line 282-286: Remove the unreachable else block that deletes
"user_emails": since emails is already validated to be non-empty earlier, simply
set userAV["user_emails"] = &types.AttributeValueMemberSS{Value: emails} (or
assign unconditionally) and delete the conditional else branch that calls
delete(userAV, "user_emails"); this cleans up dead code around the userAV,
emails and types.AttributeValueMemberSS usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91530e31-900d-4b71-892d-d55efc090e05

📥 Commits

Reviewing files that changed from the base of the PR and between 96e6104 and a9a417f.

📒 Files selected for processing (2)
  • cla-backend-legacy/internal/api/github_oauth.go
  • cla-backend-legacy/internal/api/handlers.go

@lukaszgryglicki
Copy link
Copy Markdown
Member Author

No longer needed in favor of #5037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants