Skip to content

Inconsistent lengths between QueryExpression table and fetched object #951

@iamamutt

Description

@iamamutt

Bug Report

Description

The view of a QueryExpression table and the len() method for that table report different length values from the fetched object.

Reproducibility

Include:

  • OS MACOS 11.5.2
  • Python Version 3.9.6
  • MySQL Version mysql-docker from datajoint
  • MySQL Deployment Strategy local-docker
  • DataJoint Version 1.13.2
  • Minimum number of steps to reliably reproduce the issue
import datajoint as dj
import numpy as np
import datetime

dj.conn()

dj.Schema("dj_test").drop(force=True)
schema = dj.Schema("dj_test")


@schema
class Parent(dj.Manual):
    definition = """
    # Parent table
    id: int
    ---
    txt = "NA" : varchar(32)
    """


@schema
class Child(dj.Computed):
    definition = """
    # Child table
    -> Parent
    start_time: datetime(6)
    ---
    timestamps: longblob
    """

    def make(self, key):
        t = np.random.poisson(1000, 10)
        t.sort()
        self.insert1(
            {
                "start_time": datetime.datetime.now(),
                "timestamps": t,
                **key,
            }
        )
        print(f"ingested w/ {key}")


if __name__ == "__main__":
    Parent.insert1({"id": 1})
    Child.populate()
    Parent.insert([{"id": 2}, {"id": 3}, {"id": 4}])

    q = Parent.join(Child & "id != 1", left=True)
    qf = q.fetch()

    print("\nQuery Table:\n", q)
    print("Fetched from Query Table:\n", qf)
    print("\nLength of Query Table: ", len(q))
    print("Length of Fetched obj: ", len(qf))

Output:

Connecting root@localhost:3307
ingested w/ {'id': 1}

Query Table:
 *id    *start_time    txt     timestamps
+----+ +------------+ +-----+ +--------+
2      None           NA      =BLOB=    
3      None           NA      =BLOB=    
4      None           NA      =BLOB=    
 (Total: 0)

Fetched from Query Table:
 [(2, None, 'NA', None) (3, None, 'NA', None) (4, None, 'NA', None)]

Length of Query Table:  0
Length of Fetched obj:  3

Expected Behavior

I expect the lengths of the QueryExpression and length displayed in the view to be the same as the length of the fetched object.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions