diff --git a/tests/components/automation/test_recorder.py b/tests/components/automation/test_recorder.py
index 57ed84f0d7e..7e132759a92 100644
--- a/tests/components/automation/test_recorder.py
+++ b/tests/components/automation/test_recorder.py
@@ -52,7 +52,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/calendar/test_recorder.py b/tests/components/calendar/test_recorder.py
index 918f6b82e69..38f84436d60 100644
--- a/tests/components/calendar/test_recorder.py
+++ b/tests/components/calendar/test_recorder.py
@@ -13,8 +13,8 @@ from tests.common import async_fire_time_changed
 from tests.components.recorder.common import async_wait_recording_done
 
 
-async def test_events_http_api(recorder_mock: Recorder, hass: HomeAssistant) -> None:
-    """Test the calendar demo view."""
+async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant) -> None:
+    """Test sensor attributes to be excluded."""
     await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
     await hass.async_block_till_done()
 
@@ -31,7 +31,11 @@ async def test_events_http_api(recorder_mock: Recorder, hass: HomeAssistant) ->
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/camera/test_recorder.py b/tests/components/camera/test_recorder.py
index f0888bbdfd4..d5f72fe1c91 100644
--- a/tests/components/camera/test_recorder.py
+++ b/tests/components/camera/test_recorder.py
@@ -34,7 +34,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_camera_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/climate/test_recorder.py b/tests/components/climate/test_recorder.py
index 399b7dbe4df..a2b3ac05a96 100644
--- a/tests/components/climate/test_recorder.py
+++ b/tests/components/climate/test_recorder.py
@@ -40,7 +40,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/fan/test_recorder.py b/tests/components/fan/test_recorder.py
index 3be79fbc9df..fe2cf27c98a 100644
--- a/tests/components/fan/test_recorder.py
+++ b/tests/components/fan/test_recorder.py
@@ -28,7 +28,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/group/test_recorder.py b/tests/components/group/test_recorder.py
index 9c0eaff95af..cf471ec73be 100644
--- a/tests/components/group/test_recorder.py
+++ b/tests/components/group/test_recorder.py
@@ -46,7 +46,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
                 attr_ids[
                     db_state_attributes.attributes_id
                 ] = db_state_attributes.to_native()
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = attr_ids[db_state.attributes_id]
                 native_states.append(state)
diff --git a/tests/components/humidifier/test_recorder.py b/tests/components/humidifier/test_recorder.py
index 690c2bfcc16..e0f30b65c63 100644
--- a/tests/components/humidifier/test_recorder.py
+++ b/tests/components/humidifier/test_recorder.py
@@ -34,7 +34,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_boolean/test_recorder.py b/tests/components/input_boolean/test_recorder.py
index 8bbb320e7b6..a4cc3b998da 100644
--- a/tests/components/input_boolean/test_recorder.py
+++ b/tests/components/input_boolean/test_recorder.py
@@ -34,7 +34,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_button/test_recorder.py b/tests/components/input_button/test_recorder.py
index 1a2d3c0f402..04898459987 100644
--- a/tests/components/input_button/test_recorder.py
+++ b/tests/components/input_button/test_recorder.py
@@ -34,7 +34,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_datetime/test_recorder.py b/tests/components/input_datetime/test_recorder.py
index 72df62aefb4..a59004ee06c 100644
--- a/tests/components/input_datetime/test_recorder.py
+++ b/tests/components/input_datetime/test_recorder.py
@@ -38,7 +38,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_number/test_recorder.py b/tests/components/input_number/test_recorder.py
index da51a7a35b5..982e8942c46 100644
--- a/tests/components/input_number/test_recorder.py
+++ b/tests/components/input_number/test_recorder.py
@@ -46,7 +46,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_select/test_recorder.py b/tests/components/input_select/test_recorder.py
index aa7e21278f6..5013228e6f4 100644
--- a/tests/components/input_select/test_recorder.py
+++ b/tests/components/input_select/test_recorder.py
@@ -45,7 +45,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/input_text/test_recorder.py b/tests/components/input_text/test_recorder.py
index 97819f7c444..4867d453072 100644
--- a/tests/components/input_text/test_recorder.py
+++ b/tests/components/input_text/test_recorder.py
@@ -45,7 +45,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/light/test_recorder.py b/tests/components/light/test_recorder.py
index da7c697b247..a4822b3cd74 100644
--- a/tests/components/light/test_recorder.py
+++ b/tests/components/light/test_recorder.py
@@ -35,7 +35,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/media_player/test_recorder.py b/tests/components/media_player/test_recorder.py
index e7a9aec4bb8..90e74bf54b6 100644
--- a/tests/components/media_player/test_recorder.py
+++ b/tests/components/media_player/test_recorder.py
@@ -36,7 +36,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/number/test_recorder.py b/tests/components/number/test_recorder.py
index 1c219d8a4dc..447f4bd76e6 100644
--- a/tests/components/number/test_recorder.py
+++ b/tests/components/number/test_recorder.py
@@ -30,7 +30,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/schedule/test_recorder.py b/tests/components/schedule/test_recorder.py
index 67281fc5de0..75040bc1a09 100644
--- a/tests/components/schedule/test_recorder.py
+++ b/tests/components/schedule/test_recorder.py
@@ -57,7 +57,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/script/test_recorder.py b/tests/components/script/test_recorder.py
index ea7115cc2f0..ecda80df1d9 100644
--- a/tests/components/script/test_recorder.py
+++ b/tests/components/script/test_recorder.py
@@ -68,7 +68,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/select/test_recorder.py b/tests/components/select/test_recorder.py
index 6ba62a1cc61..733949d50cf 100644
--- a/tests/components/select/test_recorder.py
+++ b/tests/components/select/test_recorder.py
@@ -30,7 +30,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py
index 7da14360a6e..4bad0fdda37 100644
--- a/tests/components/sensor/test_recorder.py
+++ b/tests/components/sensor/test_recorder.py
@@ -4735,7 +4735,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/siren/test_recorder.py b/tests/components/siren/test_recorder.py
index 645695f5012..2970754f804 100644
--- a/tests/components/siren/test_recorder.py
+++ b/tests/components/siren/test_recorder.py
@@ -30,7 +30,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/sun/test_recorder.py b/tests/components/sun/test_recorder.py
index 6012343f7c9..def5046c970 100644
--- a/tests/components/sun/test_recorder.py
+++ b/tests/components/sun/test_recorder.py
@@ -38,7 +38,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_sun_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/text/test_recorder.py b/tests/components/text/test_recorder.py
index b9a7fa67488..c434a63ace1 100644
--- a/tests/components/text/test_recorder.py
+++ b/tests/components/text/test_recorder.py
@@ -28,7 +28,11 @@ async def test_exclude_attributes(recorder_mock: Recorder, hass: HomeAssistant)
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/update/test_recorder.py b/tests/components/update/test_recorder.py
index 46588ecf45d..7e99fae51c0 100644
--- a/tests/components/update/test_recorder.py
+++ b/tests/components/update/test_recorder.py
@@ -44,7 +44,11 @@ async def test_exclude_attributes(
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/vacuum/test_recorder.py b/tests/components/vacuum/test_recorder.py
index 1ca796ba364..5da998d5944 100644
--- a/tests/components/vacuum/test_recorder.py
+++ b/tests/components/vacuum/test_recorder.py
@@ -29,7 +29,11 @@ async def test_exclude_attributes(recorder_mock, hass):
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/water_heater/test_recorder.py b/tests/components/water_heater/test_recorder.py
index 549cafc7445..901575de1da 100644
--- a/tests/components/water_heater/test_recorder.py
+++ b/tests/components/water_heater/test_recorder.py
@@ -33,7 +33,11 @@ async def test_exclude_attributes(recorder_mock, hass):
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)
diff --git a/tests/components/weather/test_recorder.py b/tests/components/weather/test_recorder.py
index 7e113ba9b83..c90da4acc23 100644
--- a/tests/components/weather/test_recorder.py
+++ b/tests/components/weather/test_recorder.py
@@ -32,7 +32,11 @@ async def test_exclude_attributes(recorder_mock, hass: HomeAssistant) -> None:
     def _fetch_states() -> list[State]:
         with session_scope(hass=hass) as session:
             native_states = []
-            for db_state, db_state_attributes in session.query(States, StateAttributes):
+            for db_state, db_state_attributes in session.query(
+                States, StateAttributes
+            ).outerjoin(
+                StateAttributes, States.attributes_id == StateAttributes.attributes_id
+            ):
                 state = db_state.to_native()
                 state.attributes = db_state_attributes.to_native()
                 native_states.append(state)