1

My project structure looks like below,

.
├── app
│   ├── api
│   ├── models
│   ├── services
│   │   └── lib
|   |   |__ worker.yaml
|   |   |__ worker.py
|   |_ main.py
|_ app.yaml

I'm trying to import models from app module (ie, default module) in worker.py like,

from app.models import db

But it shows No module named app.models. But I can achieve the same inside main.py.Note that I'm running both app.yaml and worker.yaml files.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274

1 Answers1

5

When deployed, GAE Services/modules do not share anything outside their module directory, which is the directory in which their .yaml file exists.

So worker.py won't see anything above the services dir (where worker.yaml exists), thus it can't see models. But main.py can, since models is inside its app dir (where app.yaml exists).

You could symlink models inside services if you want, see Sharing entities between App Engine modules

Or maybe take a look at Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure? for an example of how I'd structure a multi-module app?

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • so creating symbolic link for worker.yaml inside the project's root directory will work, right? I tried so, but still I can't make it to work. – Avinash Raj Feb 23 '17 at 20:11
  • Not the same thing: you'd have 2 worker.yaml files in 2 different locations. Ambiguous wrt determining the module's top dir. – Dan Cornilescu Feb 23 '17 at 23:11
  • Why do you structure your services inconsistently (one in the `.` dir and one in the `./app/services` dir? – Dan Cornilescu Feb 23 '17 at 23:35
  • does symlinking works when we deploy our app through gcloud? – Avinash Raj Feb 24 '17 at 06:25
  • symlinking works locally , just to know whether it would work on deployment through gcloud. – Avinash Raj Feb 24 '17 at 09:03
  • Yes, it works, the deployment utility replaces the symlink with the actual content. The diffference between local and GAE is visibility outside/above the module dir - visible locally, but not when deployed. – Dan Cornilescu Feb 24 '17 at 13:03
  • I'm using the same structure with creating symbolic links for app folder. It works. – Avinash Raj Feb 24 '17 at 13:06
  • Now I got another problem "ERROR: (gcloud.app.deploy) Error Response: [400] This deployment has too many files. New versions are limited to 10000 files for this app" – Avinash Raj Feb 25 '17 at 02:26
  • One of my symlinked file path shows `/home/avinash/up_project/s2s_backend/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/app/services/lib/werkzeug` – Avinash Raj Feb 25 '17 at 03:09
  • Re-check your symlinks for circular references. – Dan Cornilescu Feb 25 '17 at 03:47