Skip to content

Stop duplicating dates when duplicating questions#4502

Draft
SylvainChevalier wants to merge 2 commits intomainfrom
claude/issue-4456-stop-duplicating-dates-when-duplicating
Draft

Stop duplicating dates when duplicating questions#4502
SylvainChevalier wants to merge 2 commits intomainfrom
claude/issue-4456-stop-duplicating-dates-when-duplicating

Conversation

@SylvainChevalier
Copy link
Copy Markdown
Contributor

@SylvainChevalier SylvainChevalier commented Mar 17, 2026

Fixes #4456

When duplicating a question, skip copying scheduling date fields (open_time, scheduled_close_time, scheduled_resolve_time, cp_reveal_time, published_at) so they start empty. Bounds and zero point for date range questions are still duplicated.

Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • When creating new questions or groups by duplicating existing ones, all scheduling and timing fields (open times, close times, resolve times, and reveal times) are now reset to empty, allowing you to specify new times for your duplicates without having to manually clear values inherited from the original.

When duplicating a question (mode='create' with existing post), skip copying
scheduling date fields (open_time, scheduled_close_time, scheduled_resolve_time,
cp_reveal_time, published_at) so they start empty. Bounds (range_min, range_max)
and zero_point for date range questions are still duplicated as before.

Fixes #4456

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1fa2af7e-55a1-482f-beee-42bb78290111

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes to form component initialization logic introduce an isDuplicate flag (mode === "create" && !!post) to detect question duplication operations. When duplicating, time-related fields (scheduled_close_time, scheduled_resolve_time, open_time, cp_reveal_time) are reset to undefined instead of copying from the source post.

Changes

Cohort / File(s) Summary
Question/Group Form Components
front_end/src/app/(main)/questions/components/question_form.tsx, front_end/src/app/(main)/questions/components/group_form.tsx
Introduced isDuplicate detection flag and conditional date/time field initialization. When duplicating questions, time-related fields are set to undefined in form defaultValues and DateInput props instead of copying from the source post.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • elisescu
  • lsabor
  • hlbmtc
  • cemreinanc

Poem

🐰 Hop, hop, hooray! A clever fix so neat,
When copying questions, the dates now retreat,
Fresh times for new questions, the boundaries stay true,
Duplicates now dazzle with a temporal debut! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Stop duplicating dates when duplicating questions' clearly and concisely summarizes the main change: preventing date fields from being copied when a question is duplicated.
Linked Issues check ✅ Passed The PR successfully implements the requirements from issue #4456: skips copying scheduling dates (open_time, scheduled_close_time, scheduled_resolve_time, cp_reveal_time, published_at) while preserving range metadata (range_min, range_max, zero_point) for date-range questions.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objective of preventing date field duplication when duplicating questions, with no unrelated modifications introduced.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-4456-stop-duplicating-dates-when-duplicating

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

🚀 Preview Environment

Your preview environment is ready!

Resource Details
🌐 Preview URL https://metaculus-pr-4502-claude-issue-4456-stop-duplica-preview.mtcl.cc
📦 Docker Image ghcr.io/metaculus/metaculus:claude-issue-4456-stop-duplicating-dates-when-duplicating-3edd1be
🗄️ PostgreSQL NeonDB branch preview/pr-4502-claude-issue-4456-stop-duplica
Redis Fly Redis mtc-redis-pr-4502-claude-issue-4456-stop-duplica

Details

  • Commit: 3edd1be2c87fb4e55acad6fbb7762841aa00b385
  • Branch: claude/issue-4456-stop-duplicating-dates-when-duplicating
  • Fly App: metaculus-pr-4502-claude-issue-4456-stop-duplica

ℹ️ Preview Environment Info

Isolation:

  • PostgreSQL and Redis are fully isolated from production
  • Each PR gets its own database branch and Redis instance
  • Changes pushed to this PR will trigger a new deployment

Limitations:

  • Background workers and cron jobs are not deployed in preview environments
  • If you need to test background jobs, use Heroku staging environments

Cleanup:

  • This preview will be automatically destroyed when the PR is closed

@SylvainChevalier
Copy link
Copy Markdown
Contributor Author

lgtm.

@SylvainChevalier SylvainChevalier marked this pull request as ready for review March 19, 2026 16:25
Copy link
Copy Markdown
Contributor

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
front_end/src/app/(main)/questions/components/question_form.tsx (1)

974-980: ⚠️ Potential issue | 🟡 Minor

Missing isDuplicate check for published_at DateInput.

Per the PR objective, published_at should also be cleared during duplication. While the form's defaultValues (line 474) sets it to undefined, this DateInput component's defaultValue prop is inconsistent with the other date fields (lines 877, 890, 906, 919) that all use the isDuplicate conditional.

🔧 Proposed fix for consistency
             <DateInput
               control={form.control as unknown as Control<FieldValues>}
               name="published_at"
-              defaultValue={post?.published_at}
+              defaultValue={isDuplicate ? undefined : post?.published_at}
               errors={form.formState.errors.published_at}
               className="w-full rounded border border-gray-500 px-3 py-2 text-base dark:border-gray-500-dark dark:bg-blue-50-dark"
             />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@front_end/src/app/`(main)/questions/components/question_form.tsx around lines
974 - 980, The DateInput for published_at is missing the isDuplicate check,
causing duplication to retain the original date; update the DateInput
(name="published_at", component DateInput using form.control and
form.formState.errors) to set its defaultValue the same way as the other date
fields—i.e. use the isDuplicate conditional so defaultValue is undefined when
isDuplicate is true (instead of always using post?.published_at) to match the
form's defaultValues behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@front_end/src/app/`(main)/questions/components/question_form.tsx:
- Around line 974-980: The DateInput for published_at is missing the isDuplicate
check, causing duplication to retain the original date; update the DateInput
(name="published_at", component DateInput using form.control and
form.formState.errors) to set its defaultValue the same way as the other date
fields—i.e. use the isDuplicate conditional so defaultValue is undefined when
isDuplicate is true (instead of always using post?.published_at) to match the
form's defaultValues behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2d6a2a73-bdf8-4722-8219-588d0992b52d

📥 Commits

Reviewing files that changed from the base of the PR and between 8c53a55 and e967146.

📒 Files selected for processing (2)
  • front_end/src/app/(main)/questions/components/group_form.tsx
  • front_end/src/app/(main)/questions/components/question_form.tsx

@SylvainChevalier SylvainChevalier marked this pull request as draft March 20, 2026 10:38
@SylvainChevalier
Copy link
Copy Markdown
Contributor Author

oops I put the wrong PR up for review.

@SylvainChevalier
Copy link
Copy Markdown
Contributor Author

looks good to Nikitas.

@SylvainChevalier
Copy link
Copy Markdown
Contributor Author

@claude fix the issues from unit tests.

@claude
Copy link
Copy Markdown

claude bot commented Mar 23, 2026

Claude finished @SylvainChevalier's task in 4m 37s —— View job


Fixed CI Formatting Failure

  • Check CI status and identify failing tests
  • Fix Prettier formatting in group_form.tsx and question_form.tsx
  • Push changes

The CI failure was a Prettier formatting check (not unit tests). The defaultValue ternary expressions in question_form.tsx exceeded the 80-char print width, and group_form.tsx had an unnecessary line break in scheduled_close_time.

Fix: Ran Prettier to autoformat both files — wrapped long lines in question_form.tsx and collapsed a short ternary in group_form.tsx.
| Branch

Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
Comment on lines +473 to +475
open_time: isDuplicate ? undefined : post?.question?.open_time,
published_at: isDuplicate ? undefined : post?.published_at,
cp_reveal_time: isDuplicate ? undefined : post?.question?.cp_reveal_time,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

published_at is cleared in useForm({ defaultValues }), but the corresponding still passes defaultValue={post?.published_at} – unchanged.

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.

Stop duplicating dates when duplicating questions

2 participants