Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving entities in django-nonrel with google appengine

Update: I've noticed that entities are saved (and available at the Datastore Viewer) when I save them using views (and the create_object function). But when I use shell (manage.py shell) to create and save new entity it isn't commited to the storage (but still can be seen in Tes.objects.all()).


I started playing with the django-nonrel with google appengine and I am getting frustrated by thing as simple as saving Entities.

I've set up my environment as described in instruction. I managed to run sample application and it runs ok. I'd like to extend it so it saves my entity to the storage. To do so:

  1. I added new django module with models.py:

    from django.db import models
    
    class Tes(models.Model):
        name = models.CharField(max_length=150)
    
  2. I created a script to save some data:

    import os
    import sys
    sys.path.append("d:\\workspace\\project\\")
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    from testmodule.models import Tes
    t = Tes(name="test")
    t.save()    
    tes = Tes.objects.all()
    for t in tes:
        print t.name
    

The script runs without errrors. When I run it few times one after another, it prints more and more "test" strings. But when I try running it after a minute break the Tes.objects.all() returns nothing. During that time the datastore file changes it size (but maybe that's just some kind of logs). When I look at the http://localhost:8000/_ah/admin/datastore I can select only AhAdminXrsfToken from select field.

Anyway, what am I missing? Where I can find some kind of logs which would tell me what's wrong?

like image 433
szymond Avatar asked Nov 22 '11 12:11

szymond


People also ask

Does Google App Engine support Django?

You can deploy a PostgreSQL or MySQL database that's managed and scaled by Google, and supported by Django. You can deploy Django with a Cloud Spanner backend using the python-spanner-django database backend.

What is the difference between App Engine and Cloud run?

App Engine is for deploying code, Cloud Run for deploying containers, and containers are today's requirements. Cloud Run runs containers, so for each release you have to build a container and push it to GCP.


1 Answers

This is a gotcha that causes a lot of confusion. From the djangoappengine docs:

Also, never run manage.py runserver together with other management commands at the same time. The changes won't take effect. That's an App Engine SDK limitation which might get fixed in a later release.

So you can't do manage.py runserver and manage.py shell at the same time. If you do, changes to the datastore in one will not be visible in the other. There's a lock on the local datastore enforced by the App Engine SDK. Make sure you have stopped the server before you start the shell.

like image 132
Wilfred Hughes Avatar answered Sep 20 '22 04:09

Wilfred Hughes