datajoint-python icon indicating copy to clipboard operation
datajoint-python copied to clipboard

Spawn Missing Classes fails when called from within a method

Open guzman-raphael opened this issue 6 years ago • 0 comments
trafficstars

Test:

def init_table():
    import datajoint as dj
    
    schema = dj.schema('test_db')

    @schema
    class Person(dj.Manual):
        definition = """
        person_id : int
        ----
        full_name : varchar(60)
        """
        
    Person.insert((
        (0, 'Raphael Guzman'),
        (1, 'John Smith')
    ))
    
    print(Person())
    
def load_table():
    import datajoint as dj
    
    schema = dj.schema('test_db')
    schema.spawn_missing_classes()
    
    print(Person())
    
init_table()
load_table()

Result:

*person_id    full_name     
+-----------+ +------------+
0             Raphael Guzman
1             John Smith    
 (Total: 2)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-14-a5f530a18728> in <module>
     30 
     31 init_table()
---> 32 load_table()

<ipython-input-14-a5f530a18728> in load_table()
     27     schema.spawn_missing_classes()
     28 
---> 29     print(Person())
     30 
     31 init_table()

NameError: name 'Person' is not defined

guzman-raphael avatar Aug 07 '19 17:08 guzman-raphael