Skip to content

Refactor ListWritingCategoriesForLister query params#2762

Merged
arran4 merged 4 commits into
mainfrom
refactor-writing-categories-query-17987987312301921977
Feb 5, 2026
Merged

Refactor ListWritingCategoriesForLister query params#2762
arran4 merged 4 commits into
mainfrom
refactor-writing-categories-query-17987987312301921977

Conversation

@arran4

@arran4 arran4 commented Feb 4, 2026

Copy link
Copy Markdown
Owner

Refactored ListWritingCategoriesForLister query in internal/db/queries-writings.sql to use lister_id instead of lister_match_id.
Updated generated Go code in internal/db/queries-writings.sql.go to remove ListerMatchID from the params struct and update the function signature.
Updated core/common/coredata.go to remove ListerMatchID from the call to ListWritingCategoriesForLister.
Verified with tests in handlers/writings and core/common.


PR created automatically by Jules for task 17987987312301921977 started by @arran4

… lister_id

Updated the SQL query to remove the redundant `lister_match_id` parameter, merging it with `lister_id` as they represent the same user context.
Updated the generated Go code and `CoreData` usage to reflect this change.
This simplifies the query interface and corrects the parameter usage.

Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@arran4

arran4 commented Feb 4, 2026

Copy link
Copy Markdown
Owner Author

@jules

Run sqlc generate
# package db
error generating code: named param ListerID has incompatible types: sql.NullInt32, int32
Error: Process completed with exit code 1.

@google-labs-jules

Copy link
Copy Markdown
Contributor

@jules

Run sqlc generate
# package db
error generating code: named param ListerID has incompatible types: sql.NullInt32, int32
Error: Process completed with exit code 1.

Thank you for the catch. The sqlc error arises because ListerID is used in two contexts with different nullability inference (int32 for user_roles vs sql.NullInt32 for grants), preventing a simple merge of the SQL parameters.

I have reverted the SQL change to keep lister_id and lister_match_id distinct to satisfy sqlc's strict type checking. However, I have updated the Go code in core/common/coredata.go to correctly pass the user's ID to lister_match_id (instead of potential incorrect values), ensuring the logic behaves as intended while keeping the query valid.

Reverted the SQL parameter merge due to `sqlc` type inference conflict (`int32` vs `sql.NullInt32`).
Instead, updated `core/common/coredata.go` to correctly populate `ListerMatchID` with the user's ID, ensuring the grant check logic is correct while satisfying the type generator.

Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
@arran4

arran4 commented Feb 5, 2026

Copy link
Copy Markdown
Owner Author

@jules what are our options for unification?

@google-labs-jules

Copy link
Copy Markdown
Contributor

@jules what are our options for unification?

We have a few options to unify the parameters:

  1. Duplicate Parameters (Reverted State): Keep lister_id and lister_match_id distinct in SQL to satisfy sqlc's type inference, but populate them with the same value in Go.
  2. Force Nullability (narg): Use sqlc.narg(lister_id) in both places. This forces the generated Go parameter to be sql.NullInt32. This satisfies the nullable column comparison (g.user_id = ?) and works for the non-nullable column (ur.users_idusers = ?) because passing NULL to a non-nullable column check simply results in NULL (false), which is valid behavior for an unauthenticated user.

I have proceeded with Option 2 as it achieves the requested unification (ListerID is now the sole parameter) while maintaining type safety and correctness. I've updated the SQL, the generated code, and the usage in CoreData accordingly.

google-labs-jules Bot and others added 2 commits February 5, 2026 00:23
Updated the SQL query to use `sqlc.narg(lister_id)` for both the user lookup (CTE) and the grant check.
This forces `sqlc` to use a single `sql.NullInt32` parameter in the generated Go code, resolving the type conflict between `int32` and `sql.NullInt32`.
Updated `core/common/coredata.go` to pass the user ID as a `sql.NullInt32`.
This achieves the goal of merging `lister_id` and `lister_match_id` into a single unified parameter.

Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
@arran4 arran4 merged commit 56c6d9a into main Feb 5, 2026
9 of 14 checks passed
@arran4 arran4 deleted the refactor-writing-categories-query-17987987312301921977 branch February 5, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant