Skip to content

fix(mockup): BUG-400 — resolve HTTP 400 in generated_mockups history query#570

Merged
adm01-debug merged 2 commits into
mainfrom
fix/generated-mockups-400-missing-columns
Jun 1, 2026
Merged

fix(mockup): BUG-400 — resolve HTTP 400 in generated_mockups history query#570
adm01-debug merged 2 commits into
mainfrom
fix/generated-mockups-400-missing-columns

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented Jun 1, 2026

Bug

GET /rest/v1/generated_mockups?select=id,product_id,...,position_x,position_y,...,client_name,...
→ HTTP 400
Error fetching history: Object

Causa Raiz

PostgREST retorna HTTP 400 quando qualquer coluna no ?select= não existe na tabela. fetchMockupHistory solicitava 9 colunas que nunca foram criadas em generated_mockups:

Coluna solicitada Realidade
position_x, position_y Está em area_config JSONB
logo_width_cm, logo_height_cm Está em area_config JSONB
client_name, colors_count, annotations Está em area_config JSONB
client_id Não existe em nenhum lugar
location_name É area_name na tabela

Adicionalmente, MockupHistoryPage usava client_name.ilike.%search% num filtro .or() — também causando 400 pela mesma razão.

Correções

mockupGenerationService.ts: Substituir select explícito por select('*') e mapear area_config JSONB no resultado. Interface GeneratedMockup preservada — consumidores não percebem mudança.

MockupHistoryPage.tsx:

  • Remover client_name.ilike do filtro .or() → substituído por technique_name.ilike
  • Adicionar mapper inline de area_config para client_name, location_name, dimensões da logo
  • Placeholder do input atualizado: "Buscar por produto, SKU ou técnica..." (cliente não é pesquisável via SQL)

Summary by cubic

Fixes HTTP 400 errors in generated mockups history by selecting only real columns and mapping JSONB fields from area_config. Also removes the invalid client_name search filter to prevent 400s on the history page. (BUG-400)

  • Bug Fixes
    • fetchMockupHistory: use .select('*') and map area_config JSONB into the flat GeneratedMockup shape (position_x/y, logo_width_cm/height_cm, client_name, colors_count, annotations; location_name from area_name) to avoid selecting non-existent columns.
    • MockupHistoryPage: removed client_name.ilike from the .or() filter; replaced with technique_name.ilike. Added inline area_config mapper and updated the search placeholder.

Written for commit ea882e9. Summary will update on new commits.

Review in cubic

PostgREST returns HTTP 400 when any column in ?select= doesn't exist in
the table. fetchMockupHistory was requesting 9 columns that were never
added to generated_mockups:
  - position_x, position_y, logo_width_cm, logo_height_cm → in area_config JSONB
  - client_id, client_name, location_name, colors_count, annotations → in area_config JSONB

Fix: use .select('*') and remap area_config fields in a JS mapper.
The GeneratedMockup interface shape is preserved — consumers see the same
flat structure they expected.
…n't exist)

Secondary fix: MockupHistoryPage search used client_name.ilike which
causes a 400 because client_name is not a column on generated_mockups.
Replaced with technique_name.ilike.

Also: inline the area_config JSONB mapper in MockupHistoryPage so the
component gets client_name, location_name, and logo dimensions correctly
from the JSONB field without relying on fetchMockupHistory.
Copilot AI review requested due to automatic review settings June 1, 2026 11:54
@supabase
Copy link
Copy Markdown

supabase Bot commented Jun 1, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
we-dream-big Error Error Jun 1, 2026 11:54am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 45 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd500ebb-9f84-46a6-bc28-267b088efe76

📥 Commits

Reviewing files that changed from the base of the PR and between a28de29 and ea882e9.

📒 Files selected for processing (2)
  • src/hooks/mockup/mockupGenerationService.ts
  • src/pages/mockups/MockupHistoryPage.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/generated-mockups-400-missing-columns

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/hooks/mockup/mockupGenerationService.ts">

<violation number="1" location="src/hooks/mockup/mockupGenerationService.ts:230">
P0: `generateMockupApi` now sends a payload schema that the `generate-mockup` edge function does not accept, causing validation 400s.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}
const generateCall = supabase.functions.invoke('generate-mockup', {
body: {
productImage: params.productImage,
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.

P0: generateMockupApi now sends a payload schema that the generate-mockup edge function does not accept, causing validation 400s.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/hooks/mockup/mockupGenerationService.ts, line 230:

<comment>`generateMockupApi` now sends a payload schema that the `generate-mockup` edge function does not accept, causing validation 400s.</comment>

<file context>
@@ -252,163 +213,46 @@ export interface GenerateMockupParams {
-  }
+  const generateCall = supabase.functions.invoke('generate-mockup', {
+    body: {
+      productImage: params.productImage,
+      productName: params.productName,
+      technique: params.technique,
</file context>

@adm01-debug adm01-debug merged commit 15a7dcb into main Jun 1, 2026
29 of 38 checks passed
@adm01-debug adm01-debug deleted the fix/generated-mockups-400-missing-columns branch June 1, 2026 12:06
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants