Title: Use of imported schema object · Issue #413 · datajoint/datajoint-python · GitHub
Open Graph Title: Use of imported schema object · Issue #413 · datajoint/datajoint-python
X Title: Use of imported schema object · Issue #413 · datajoint/datajoint-python
Description: Currently, when you create a schema object in one module (i.e. Python file) using locals() and then import that schema object and use it to decorate a DataJoint user relation class, the lookup of foreign key names does not work. For exam...
Open Graph Description: Currently, when you create a schema object in one module (i.e. Python file) using locals() and then import that schema object and use it to decorate a DataJoint user relation class, the lookup of f...
X Description: Currently, when you create a schema object in one module (i.e. Python file) using locals() and then import that schema object and use it to decorate a DataJoint user relation class, the lookup of f...
Opengraph URL: https://github.com/datajoint/datajoint-python/issues/413
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use of imported schema object","articleBody":"Currently, when you create a schema object in one module (i.e. Python file) using `locals()` and then import that schema object and use it to decorate a DataJoint user relation class, the lookup of foreign key names does not work. For example:\r\n\r\n`module1.py`\r\n```python\r\nimport datajoint as dj\r\n\r\nschema = dj.schema('my_schema', locals())\r\n\r\n@schema\r\nclass A(dj.Manual):\r\n definiton = \"\"\"\r\n id: int # id\r\n \"\"\"\r\n\r\n# this works just fine\r\n@schema\r\nclass B(dj.Manual):\r\n definition = \"\"\"\r\n -\u003e A\r\n \"\"\"\r\n```\r\n\r\n`module2.py`\r\n```python\r\nimport datajoint as dj\r\nfrom .module1 import schema # importing schema object\r\n\r\n# this still works because no foreign key reference made\r\n@schema\r\nclass C(dj.Manual):\r\n definition = \"\"\"\r\n id: int # id\r\n \"\"\"\r\n\r\n# however, this doesn't work because imported schema object cannot look at the *current local* context\r\n@schema\r\nclass D(dj.Manual):\r\n definition = \"\"\"\r\n -\u003e C\r\n \"\"\"\r\n```\r\n\r\nAlthough this behavior is completely consistent and thus is expected based on how `locals()` work, the result is certainly counter-intuitive and may be error prone - especially because some cases of using imported schema object (e.g. when defining class `C` in the above example) actually works.\r\n\r\nIn conjunction to fixing #368 as aimed by #412 , I suggest that we also let `dj.schema('schema_name')` to be aware of the local context it is currently present **regardless of where it was defiend**.","author":{"url":"https://github.com/eywalker","@type":"Person","name":"eywalker"},"datePublished":"2017-12-14T02:19:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/413/datajoint-python/issues/413"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6d67db4-7e5f-e131-611b-34b4d1d8cc22 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8640:11EE4:1CE0D11:27B784D:6A4EBA17 |
| html-safe-nonce | c82343aba781b189cb1bcee17976a5d7c69f24d279ce8766776d93f3c02d71e7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjQwOjExRUU0OjFDRTBEMTE6MjdCNzg0RDo2QTRFQkExNyIsInZpc2l0b3JfaWQiOiI2MjU3MTMyNDIyNzQ1MjA5MzY3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3e579937ad6f12c7379f3bb41d0624787a3fd9cddee3871941f13b518c2d37d8 |
| hovercard-subject-tag | issue:281960247 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/datajoint/datajoint-python/413/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b74d32b55512f2f199f9f8961284dff7c1d509de6e4e8bc26fb6347039bdde8a/datajoint/datajoint-python/issues/413 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b74d32b55512f2f199f9f8961284dff7c1d509de6e4e8bc26fb6347039bdde8a/datajoint/datajoint-python/issues/413 |
| og:image:alt | Currently, when you create a schema object in one module (i.e. Python file) using locals() and then import that schema object and use it to decorate a DataJoint user relation class, the lookup of f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eywalker |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/datajoint/datajoint-python git https://github.com/datajoint/datajoint-python.git |
| octolytics-dimension-user_id | 2375501 |
| octolytics-dimension-user_login | datajoint |
| octolytics-dimension-repository_id | 5866704 |
| octolytics-dimension-repository_nwo | datajoint/datajoint-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 5866704 |
| octolytics-dimension-repository_network_root_nwo | datajoint/datajoint-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width