Ich versuche, eine Abfrage in Python mit SQLAlchemy auszuführen, um alle WLCs in der Tabelle mit diesem Code abzurufen:
Code: Select all
with create_new_session() as session:
statement = select(Location.wlc)
rows = session.exec(statement).all()
Wenn keine Datensätze in der Tabelle vorhanden sind, schlägt der Code fehl.
Unter dem Deckmantel erstellt SQLAlchemy diese Abfrage für mich:
Code: Select all
SELECT "LOCATIONS"."LOCS"."WLC" FROM "LOCATIONS"."LOCS"
Code: Select all
statement = text('SELECT "LOCATIONS"."LOCS"."WLC" FROM "LOCATIONS"."LOCS"')
Code: Select all
statement = text('SELECT LOCS.WLC FROM LOCS')
Die Ausnahme, die ausgelöst wird, ist:
Code: Select all
File "/home/genaro/Documents/worklocations/src/work_locations/jobs/handlers/extract.py", line 240, in _get_db2_wlcs
rows = session.exec(statement).all()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1476, in all
return self._allrows()
^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 401, in _allrows
rows = self._fetchall_impl()
^^^^^^^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1389, in _fetchall_impl
return self._real_result._fetchall_impl()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 1813, in _fetchall_impl
return list(self.iterator)
^^^^^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/orm/loading.py", line 147, in chunks
fetch = cursor._raw_all_rows()
^^^^^^^^^^^^^^^^^^^^^^
File "/home/genaro/Documents/worklocations/venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py", line 393, in _raw_all_rows
return [make_row(row) for row in rows]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable
Irgendwelche Ideen? Mache ich etwas falsch? Vielen Dank im Voraus.
Mobile version