query.all() returning 1 when actual query returns 2?

20 views
Skip to first unread message

Michael P. McDonnell

unread,
Aug 2, 2019, 3:11:15 PM8/2/19
to sqlal...@googlegroups.com
So when I generate the query with SQL Alchemy (using the ORM) I get the following:

SELECT game_leaderboard.game_id, game_leaderboard.person_id, game_leaderboard.display_name, game_leaderboard.total_tasks, game_leaderboard.tasks_completed, game_leaderboard.duration
FROM game_leaderboard
WHERE game_leaderboard.game_id = %(game_id_1)s
Data: game_id='5184b7eb-b687-4471-8aa9-7b6715b7a9aa'

I get the following result: 
[
    {
        "total_tasks": 2,
        "display_name": "Auto Test ",
        "tasks_completed": 2,
        "person_id": "96736b38-b854-403c-90d8-0701c23efe55",
        "duration": "0:08:00",
        "game_id": "5184b7eb-b687-4471-8aa9-7b6715b7a9aa"
    }
]

However when I run this same query (generated) in psql:
odyssey=# SELECT game_leaderboard.game_id, game_leaderboard.person_id, game_leaderboard.display_name, game_leaderboard.total_tasks, game_leaderboard.tasks_completed, game_leaderboard.duration
FROM game_leaderboard
WHERE game_leaderboard.game_id = '5184b7eb-b687-4471-8aa9-7b6715b7a9aa';
               game_id                |              person_id               | display_name | total_tasks | tasks_completed | duration
--------------------------------------+--------------------------------------+--------------+-------------+-----------------+----------
 5184b7eb-b687-4471-8aa9-7b6715b7a9aa | 96736b38-b854-403c-90d8-0701c23efe55 | Auto Test    |           2 |               2 | 00:08:00
 5184b7eb-b687-4471-8aa9-7b6715b7a9aa | ac370ba6-0ea8-4068-8cac-0337b6807481 | Auto Test    |           2 |               2 | 00:16:00

I have determined however - if I change the "display_name" to something different between the two people, I suddenly get 2 results from query.all()

This is doing a query on a VIEW. 

Any ideas on where I can start looking at this?

Michael P. McDonnell

unread,
Aug 2, 2019, 3:16:44 PM8/2/19
to sqlal...@googlegroups.com
Oh! I should add - when do a len() on the results of query.all() - I Get 1 until I change the display_name

Michael P. McDonnell

unread,
Aug 2, 2019, 4:18:58 PM8/2/19
to sqlal...@googlegroups.com
Holy buckets I found it. 

I had this:
    display_name = Column(
        'display_name', String(length=255), nullable=False, primaryKey=True)
That little primaryKey bit right there, not supposed to be there.
Reply all
Reply to author
Forward
0 new messages