datajoint-python
datajoint-python copied to clipboard
Master table method querying part table drops restrictions
trafficstars
Bug Report
Description
In a master table method, a query on the part table seems to disassociate from any restrictions done on the master self. Below is the code that adds several methods that do queries both on the master table, and on the part table.
Reproducibility
- OS: MACOS
- Python Version: 3.8.10
- MySQL Version: 5.7
- MySQL Deployment Strategy: Google Cloud SQL
- DataJoint Version: 0.13.2
import datajoint as dj
schema = dj.schema("test_part_self")
@schema
class Acquisition(dj.Manual):
definition = """
main_key: int
"""
class Part(dj.Part):
definition = """
-> Acquisition
part_key: int
"""
def get_main(self):
return self.fetch()
def get2_main(self, key):
return (self & key).fetch()
def get_part(self):
return self.Part.fetch()
def get2_part(self, key):
return (self.Part & key).fetch()
# Insert some data.
for main_key in range(3):
Acquisition.insert1({'main_key': main_key})
for part_key in range(10 * main_key, 10*main_key + 2):
Acquisition.Part.insert1({'main_key': main_key, 'part_key': part_key})
key = {'main_key': 1}
# I expect the following two to be identical.
print((Acquisition() & key).get_main())
print(Acquisition().get2_main(key))
print()
# I expect the following two to be identical.
print((Acquisition() & key).get_part())
print(Acquisition().get2_part(key))
[(1,)]
[(1,)]
[(0, 0) (0, 1) (1, 10) (1, 11) (2, 20) (2, 21)] # <-- Why is whole table returned?
[(1, 10) (1, 11)]
Expected Behavior
I expect that doing a restriction via key before calling get_part should respect that restriction.
[(1,)]
[(1,)]
[(1, 10) (1, 11)]
[(1, 10) (1, 11)]