Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session.query(pycram.orm.base.ProcessMetaData).all() returns only one object #118

Open
Leusmann opened this issue Dec 22, 2023 · 0 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@Leusmann
Copy link
Collaborator

Leusmann commented Dec 22, 2023

Summery

I am trying to query all ProcessMetaData from my local postgres database, using the ORM.
But using the following command response = session.query(pycram.orm.base.ProcessMetaData).all() returns only a list containing one object instead of all objects as expected.

Detailed

I am using the following postgres version:
PostgreSQL 14.10 (Ubuntu 14.10-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit

My ProcessMetaData has the following definition:

pycram=# \d "ProcessMetaData" 
                                           Table "public.ProcessMetaData"
     Column     |            Type             | Collation | Nullable |                    Default                    
----------------+-----------------------------+-----------+----------+-----------------------------------------------
 created_at     | timestamp without time zone |           | not null | CURRENT_TIMESTAMP
 created_by     | character varying(255)      |           | not null | 
 description    | character varying(255)      |           | not null | 
 pycram_version | character varying(255)      |           |          | 
 id             | integer                     |           | not null | nextval('"ProcessMetaData_id_seq"'::regclass)
Indexes:
    "ProcessMetaData_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE ""Code"" CONSTRAINT "code_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Color"" CONSTRAINT "color_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Designator"" CONSTRAINT "designator_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Object"" CONSTRAINT "object_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Pose"" CONSTRAINT "pose_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Position"" CONSTRAINT "position_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""Quaternion"" CONSTRAINT "quaternion_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""RobotState"" CONSTRAINT "robotstate_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE
    TABLE ""TaskTreeNode"" CONSTRAINT "tasktreenode_process_metadata_id_fkey" FOREIGN KEY (process_metadata_id) REFERENCES "ProcessMetaData"(id) ON UPDATE CASCADE

It contains the following data:

pycram=# select * from "ProcessMetaData";
         created_at         | created_by |                     description                     |              pycram_version              | id 
----------------------------+------------+-----------------------------------------------------+------------------------------------------+----
 2023-12-22 14:16:49.281148 | nleusmann  | Unittest: All that is gold does not glitter, 0      | af343656dd2d615259c5df4543b56260cf8d358e |  7
 2023-12-22 14:17:01.399586 | nleusmann  | Unittest: Not all those who wander are lost; 1      | af343656dd2d615259c5df4543b56260cf8d358e |  8
 2023-12-22 14:17:13.865826 | nleusmann  | Unittest: The old that is strong does not wither, 2 | af343656dd2d615259c5df4543b56260cf8d358e |  9
 2023-12-22 13:22:11        | nleusmann  | Database merger Unittest: Example pick and place 0  | af343656dd2d615259c5df4543b56260cf8d358e | 10
 2023-12-22 13:22:24        | nleusmann  | Database merger Unittest: Example pick and place 1  | af343656dd2d615259c5df4543b56260cf8d358e | 11
 2023-12-22 13:22:36        | nleusmann  | Database merger Unittest: Example pick and place 2  | af343656dd2d615259c5df4543b56260cf8d358e | 12
 2023-12-22 13:22:11        | nleusmann  | Database merger Unittest: Example pick and place 0  | af343656dd2d615259c5df4543b56260cf8d358e |  1
 2023-12-22 13:22:24        | nleusmann  | Database merger Unittest: Example pick and place 1  | af343656dd2d615259c5df4543b56260cf8d358e |  2
 2023-12-22 13:22:36        | nleusmann  | Database merger Unittest: Example pick and place 2  | af343656dd2d615259c5df4543b56260cf8d358e |  3
 2023-12-22 13:22:50        | nleusmann  | Database merger Unittest: Example pick and place 0  | af343656dd2d615259c5df4543b56260cf8d358e |  4
 2023-12-22 13:23:03        | nleusmann  | Database merger Unittest: Example pick and place 1  | af343656dd2d615259c5df4543b56260cf8d358e |  5
 2023-12-22 13:23:15        | nleusmann  | Database merger Unittest: Example pick and place 2  | af343656dd2d615259c5df4543b56260cf8d358e |  6

When using the response = session.query(pycram.orm.base.ProcessMetaData).all() command, the only value that gets returned is the following:

[ProcessMetaData(id=6, created_at=datetime.datetime(2023, 12, 22, 13, 23, 15), created_by='nleusmann', description='Database merger Unittest: Example pick and place 2', pycram_version='af343656dd2d615259c5df4543b56260cf8d358e')]

Which is the most recently added object.
Curiously the count = session.query(pycram.orm.base.ProcessMetaData).count() returns the correct amount of 12.

Utilizing the select statement.

select_statement = sqlalchemy.select('*').select_from(pycram.orm.base.ProcessMetaData)
select_result = session.execute(select_statement).all()

I receive the expected return value:

[(datetime.datetime(2023, 12, 22, 14, 16, 49, 281148), 'nleusmann', 'Unittest: All that is gold does not glitter, 0', 'af343656dd2d615259c5df4543b56260cf8d358e', 7), (datetime.datetime(2023, 12, 22, 14, 17, 1, 399586), 'nleusmann', 'Unittest: Not all those who wander are lost; 1', 'af343656dd2d615259c5df4543b56260cf8d358e', 8), (datetime.datetime(2023, 12, 22, 14, 17, 13, 865826), 'nleusmann', 'Unittest: The old that is strong does not wither, 2', 'af343656dd2d615259c5df4543b56260cf8d358e', 9), (datetime.datetime(2023, 12, 22, 13, 22, 11), 'nleusmann', 'Database merger Unittest: Example pick and place 0', 'af343656dd2d615259c5df4543b56260cf8d358e', 10), (datetime.datetime(2023, 12, 22, 13, 22, 24), 'nleusmann', 'Database merger Unittest: Example pick and place 1', 'af343656dd2d615259c5df4543b56260cf8d358e', 11), (datetime.datetime(2023, 12, 22, 13, 22, 36), 'nleusmann', 'Database merger Unittest: Example pick and place 2', 'af343656dd2d615259c5df4543b56260cf8d358e', 12), (datetime.datetime(2023, 12, 22, 13, 22, 11), 'nleusmann', 'Database merger Unittest: Example pick and place 0', 'af343656dd2d615259c5df4543b56260cf8d358e', 1), (datetime.datetime(2023, 12, 22, 13, 22, 24), 'nleusmann', 'Database merger Unittest: Example pick and place 1', 'af343656dd2d615259c5df4543b56260cf8d358e', 2), (datetime.datetime(2023, 12, 22, 13, 22, 36), 'nleusmann', 'Database merger Unittest: Example pick and place 2', 'af343656dd2d615259c5df4543b56260cf8d358e', 3), (datetime.datetime(2023, 12, 22, 13, 22, 50), 'nleusmann', 'Database merger Unittest: Example pick and place 0', 'af343656dd2d615259c5df4543b56260cf8d358e', 4), (datetime.datetime(2023, 12, 22, 13, 23, 3), 'nleusmann', 'Database merger Unittest: Example pick and place 1', 'af343656dd2d615259c5df4543b56260cf8d358e', 5), (datetime.datetime(2023, 12, 22, 13, 23, 15), 'nleusmann', 'Database merger Unittest: Example pick and place 2', 'af343656dd2d615259c5df4543b56260cf8d358e', 6)]

But instead of an list of all the different ProcessMetaData stored within my database I only receive an single object.
What is even more surprising is the fact that the counting command returns the :

count = session.query(pycram.orm.base.ProcessMetaData).count()

returns the correct amount of possible objects.

If needed I can provide additional information, please just ask.

@tomsch420 tomsch420 added the good first issue Good for newcomers label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants