Here's a comprehensive Discord post for the Supabase community: --- ## ๐Ÿšจ **CRITICAL BUG: Supabase Automatically Injecting ON CONFLICT into Simple INSERT Operations** ### **๏ฟฝ๏ฟฝ What I'm Trying to Achieve:** I'm trying to perform a simple INSERT operation into a `habit_completions` table to record when users complete their habits. This is a basic CRUD operation that should work without any conflict handling. ### **โŒ What's Going Wrong:** Supabase is automatically injecting `ON CONFLICT` clauses into my INSERT operations, even when I don't want them. This causes the error: ``` {"code":"42P10","details":null,"hint":null,"message":"there is no unique or exclusion constraint matching the ON CONFLICT specification"} ``` ### **๐Ÿ” Detailed Problem Description:** **My Operation:** ```sql INSERT INTO public.habit_completions ( habit_id, user_id, notes, mood_score, energy_level, difficulty_level, completed_at ) VALUES ( '056a574c-b4b4-436a-bdc5-43c51fc5dd1f', '3206739b-22fa-4325-8e27-e7124ba31c13', 'Test completion', 8, 7, 4, NOW() ); ``` **What Supabase is doing (incorrectly):** ```sql INSERT INTO public.habit_completions (...) VALUES (...) ON CONFLICT (habit_id, user_id, completed_at) DO UPDATE SET ... ``` **My Database Constraints (all valid):** ```sql -- Table definition CREATE TABLE public.habit_completions ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, habit_id UUID NOT NULL REFERENCES public.habits(id) ON DELETE CASCADE, user_id UUID NOT NULL REFERENCES public.profiles(id) ON DELETE CASCADE, completed_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), notes TEXT, mood_score INTEGER CHECK (mood_score >= 1 AND mood_score <= 10), energy_level INTEGER CHECK (energy_level >= 1 AND energy_level <= 10), difficulty_level INTEGER CHECK (difficulty_level >= 1 AND difficulty_level <= 10), location VARCHAR(100), weather VARCHAR(50), created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), UNIQUE(habit_id, user_id, DATE(completed_at)) ); -- Additional indexes I created CREATE UNIQUE INDEX habit_completion_daily_ts_idx ON public.habit_completions (habit_id, user_id, completed_at); CREATE UNIQUE INDEX habit_completion_daily_idx ON public.habit_completions (habit_id, user_id, completion_date); ``` ### **๐Ÿงช What I've Tried:** 1. **Supabase Python Client (all versions):** ```python # Simple insert response = client.table("habit_completions").insert(data).execute() # With conflict_target=None response = client.table("habit_completions").insert(data, conflict_target=None).execute() # With empty on_conflict response = client.table("habit_completions").insert(data).on_conflict("").execute() ``` 2. **RPC Functions:** ```python response = client.rpc("insert_habit_completion", params).execute() ``` 3. **Direct REST API:** ```python response = await client.post(f"{SUPABASE_URL}/rest/v1/habit_completions", json=data, headers=headers) ``` 4. **Direct PostgreSQL Connection:** ```python await conn.execute("INSERT INTO public.habit_completions (...) VALUES (...)") ``` **ALL methods fail with the same ON CONFLICT error.** ### **๐Ÿ”ง Environment Details:** - **OS:** Windows 10 (10.0.26100) - **Framework:** FastAPI (Python) - **Platform:** Web backend - **Supabase Python Client:** `supabase==2.18.1` (also tested 2.5.0, 2.18.0) - **Database:** Supabase PostgreSQL - **Python:** 3.12 - **Additional Libraries:** `asyncpg==0.30.0`, `httpx==0.27.2` ### **๐Ÿšจ Critical Issue:** This appears to be a **platform-wide Supabase bug** where: 1. **Automatic ON CONFLICT injection** is broken 2. **Constraint detection** is broken 3. **Even REST API calls** are affected 4. **The bug affects multiple client versions** ### **๐Ÿ’ก Expected Behavior:** A simple INSERT should work without any automatic conflict handling. If I want ON CONFLICT, I should explicitly request it. ### **๐ŸŽฏ Question:** Is this a known issue? Are there any workarounds? This is blocking a core feature of my application (habit completion tracking). **Tags:** `#bug` `#python` `#database` `#insert` `#on-conflict` --- **Additional Context:** This is affecting a productivity companion app where users need to mark habits as completed. The habit completion feature is completely broken due to this Supabase issue, while all other CRUD operations (tasks, goals, mood tracking) work perfectly.