Skip to content

Bug: Session Replay filter by OS/browser/country/device causes PostgreSQL LATERAL error #4299

@world1dan

Description

@world1dan

Describe the Bug

Filtering the Session Replay table by OS (or browser, country, device) causes a 500 error.

Steps to Reproduce

  1. Open the Session Replay page
  2. Apply a filter on OS (or browser / country / device)
  3. Observe 500 error

Related

Similar bug previously seen in #3545 (session_data) and #3255 (referrer filter).

Database

PostgreSQL

Relevant log output

2026-05-25 11:52:27.121 UTC [69] ERROR:  invalid reference to FROM-clause entry for table "session" at character 962
2026-05-25 11:52:27.121 UTC [69] DETAIL:  There is an entry for table "session", but it cannot be referenced from this part of the query.
2026-05-25 11:52:27.121 UTC [69] HINT:  To reference that table, you must mark this subquery with LATERAL.
2026-05-25 11:52:27.121 UTC [69] STATEMENT:  select count(*) as num from (
	    select
	      sr.visit_id as "id",
	      sr.session_id as "sessionId",
	      sr.website_id as "websiteId",
	      session.browser,
	      session.os,
	      session.device,
	      session.country,
	      session.city,
	      sum(sr.event_count) as "eventCount",
	      count(sr.replay_id) as "chunkCount",
	      min(sr.started_at) as "startedAt",
	      max(sr.ended_at) as "endedAt",
	      sum(extract(epoch from sr.ended_at - sr.started_at) * 1000)::bigint as "duration",
	      max(sr.created_at) as "createdAt"
	    from session_replay sr
	    join session on session.session_id = sr.session_id
	      and session.website_id = sr.website_id
	    join (select distinct website_event.website_id, website_event.session_id, website_event.visit_id
	               from website_event
	               
	    order by max(sr.created_at) desc
	               where website_event.website_id = $1::uuid
	                  and website_event.created_at between $2 and $3
	    ) t
	    where sr.website_id = $5::uuid
	                  and session.os = ANY($4)) website_event

Which Umami version are you using?

3.1.0

How are you deploying your application?

Railway

Which browser are you using?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions