2

DataJoint version 0.13.4

Python 3.9, running in PyCharm 2022.1.1 Pro Edition

MacOS 12.3.1

I've been working with several of the datajoint-elements packages just trying to get an overall schema created so I can see what new schema's, if any, need to be created for hosting our lab's data. The blank for the class in the title is because I have seen this with several different classes while trying to get this setup, such as Class Session or Class SessionNote. In the code below, Class SessionNote is what the actual error was for, but I figured a more general question may help others in the future!

What I especially find interesting is that this error occurs when just calling the draw function for lab which by itself does not have any reference to SessionNote. I also tried not activating the other schema by commenting them out, and then would instead get the same error, but for Class Subject not being properly declared. I have double checked and all the classes that are claiming to not be properly declared are active within the namespace of the environment. I have also gotten this error when trying to insert data into a table, though that seems fixed after I updated one of the elements packages straight from github instead of PyPi. Let me know if there is any additional information I can provide to help! It's my first submission to Stack Overflow

import datetime

import datajoint as dj
import wehrdj
from element_session import session
from element_animal import subject, genotyping
from element_lab import lab


from element_animal.subject import Subject
from element_animal.genotyping import Sequence, BreedingPair, Cage,\
                                      SubjectCaging, GenotypeTest
from element_lab.lab import Source, Lab, Protocol, User, Project, ProjectUser, \
                            ProjectKeywords, ProjectPublication, ProjectSourceCode
from element_session.session_with_datetime import Session, SessionDirectory, \
                            SessionExperimenter, SessionNote, \
                            ProjectSession
from element_animal.export.nwb import subject_to_nwb
from element_lab.export.nwb import element_lab_to_nwb_dict

wehrdj.connect()  # Wrapper for dj.connect(), can be replaced with the normal DJ function if needed

db_prefix = dj.config['custom'].get('database.prefix', '')

__all__ = ['genotyping', 'session', 'Subject', 'Source', 'Lab', 'Protocol', 'User',
           'Project', 'ProjectKeywords', 'ProjectPublication', 'ProjectSourceCode',
           'ProjectUser', 'Session', 'SessionDirectory', 'SessionExperimenter',
           'SessionNote', 'ProjectSession', 'Sequence', 'BreedingPair', 'Cage',
           'SubjectCaging', 'GenotypeTest']

Experimenter = lab.User

# Testing activations
lab.activate(db_prefix + "lab")
subject.activate(db_prefix + "subject", linking_module=__name__)
session.activate(db_prefix + "session", linking_module=__name__)
genotyping.activate(db_prefix + "genotyping", db_prefix + "subject", linking_module=__name__)

# Testing drawing schema
dj.Diagram(lab).draw()

  • I think the public version of element-session offers 2 options depending on how you want to identify a session. You might change the import to `from element_session import session_with_id as session` – Chris Broz May 23 '22 at 17:23
  • Changing both element-session calls to specify `from element_session import session_with_id as session` and `from element_session.session_with_id import Session, SessionDirectory, SessionExperimenter, SessionNote, ProjectSession` still seems to result in the same initial error. I did notice that when calling session as I did, it does default to calling the `session_with_datetime` option, but I agree your suggestion is better for readability! – Spider Pig 212 May 23 '22 at 18:14
  • 1
    Hmm, not sure. Can it be stripped down to an MVP? I would save the above as `pipeline.py` with just the lab items. And then `from project.pipeline import lab` - if you run `dj.conn()`, is there a lab schema on the server? // Minor additional note: `genotyping.activate` can bump up 2 lines and replace `subject.activate` - Genotyping is one of the schemas that activates another schema in the same element. – Chris Broz May 23 '22 at 20:01
  • So separating it into just the lab items did cause the lab schema to diagram properly! I went back to the original code I submitted above and that actually works too now with no modifications. Is there any inkling as to why running the separate lab instance first has solved this problem? – Spider Pig 212 May 23 '22 at 21:41
  • Sorry, no, not sure why. It does seem specific to the Element activation process. Production schemas elsewhere [e.g.](https://github.com/BrainCOGS/U19-pipeline_python/blob/master/u19_pipeline/behavior.py) don't need the same activation because they know the prefix+schema name at time of declaration. I might be able to tell you more with the full error stack. Could be something with the connection? – Chris Broz May 24 '22 at 20:20

0 Answers0