why does POST not see attribute set in GET
I do not understand why the POST method in GAE does not see an attribute set in GET when GET is run before POST. the following is a simple illustration:
app.yaml
application: post-does-not-see-get
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: index.py
index.py
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
class MainHandler(webapp.RequestHandler):
formstring = '''<form method="post" action="/">
<p>Enter sth: <input type="text" name="sth"/></p>
<p><input type="submit"></p></form>'''
def get(self):
self.a=5
logging.info('a: '+str(self.a))
self.response.out.write(self.formstring)
def post(self):
self.response.out.write('<p>'+self.a+'</p>n')
self.response.out.write(self.formstring)
def main():
application = webapp.WSGIApplication(
[('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
while the following shows that post sees the change made in get
class B:
a=3
def get(self):
self.a=4
def post(self):
print('a from post: '+str(self.a))
q=B()
q.post()
q.get()
q.post()
python google-app-engine google-cloud-platform
add a comment |
I do not understand why the POST method in GAE does not see an attribute set in GET when GET is run before POST. the following is a simple illustration:
app.yaml
application: post-does-not-see-get
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: index.py
index.py
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
class MainHandler(webapp.RequestHandler):
formstring = '''<form method="post" action="/">
<p>Enter sth: <input type="text" name="sth"/></p>
<p><input type="submit"></p></form>'''
def get(self):
self.a=5
logging.info('a: '+str(self.a))
self.response.out.write(self.formstring)
def post(self):
self.response.out.write('<p>'+self.a+'</p>n')
self.response.out.write(self.formstring)
def main():
application = webapp.WSGIApplication(
[('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
while the following shows that post sees the change made in get
class B:
a=3
def get(self):
self.a=4
def post(self):
print('a from post: '+str(self.a))
q=B()
q.post()
q.get()
q.post()
python google-app-engine google-cloud-platform
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52
add a comment |
I do not understand why the POST method in GAE does not see an attribute set in GET when GET is run before POST. the following is a simple illustration:
app.yaml
application: post-does-not-see-get
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: index.py
index.py
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
class MainHandler(webapp.RequestHandler):
formstring = '''<form method="post" action="/">
<p>Enter sth: <input type="text" name="sth"/></p>
<p><input type="submit"></p></form>'''
def get(self):
self.a=5
logging.info('a: '+str(self.a))
self.response.out.write(self.formstring)
def post(self):
self.response.out.write('<p>'+self.a+'</p>n')
self.response.out.write(self.formstring)
def main():
application = webapp.WSGIApplication(
[('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
while the following shows that post sees the change made in get
class B:
a=3
def get(self):
self.a=4
def post(self):
print('a from post: '+str(self.a))
q=B()
q.post()
q.get()
q.post()
python google-app-engine google-cloud-platform
I do not understand why the POST method in GAE does not see an attribute set in GET when GET is run before POST. the following is a simple illustration:
app.yaml
application: post-does-not-see-get
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: index.py
index.py
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
class MainHandler(webapp.RequestHandler):
formstring = '''<form method="post" action="/">
<p>Enter sth: <input type="text" name="sth"/></p>
<p><input type="submit"></p></form>'''
def get(self):
self.a=5
logging.info('a: '+str(self.a))
self.response.out.write(self.formstring)
def post(self):
self.response.out.write('<p>'+self.a+'</p>n')
self.response.out.write(self.formstring)
def main():
application = webapp.WSGIApplication(
[('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
while the following shows that post sees the change made in get
class B:
a=3
def get(self):
self.a=4
def post(self):
print('a from post: '+str(self.a))
q=B()
q.post()
q.get()
q.post()
python google-app-engine google-cloud-platform
python google-app-engine google-cloud-platform
edited Dec 18 '18 at 9:26
Maxim
1,553211
1,553211
asked Nov 21 '18 at 16:56
StephenStephen
538
538
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52
add a comment |
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52
add a comment |
1 Answer
1
active
oldest
votes
Don't try and store state in classes across requests. GAE, like most web environments, runs multiple processes - potentially in multiple separate containers or even datacentres - to serve your requests. There is absolutely no guarantee that subsequent requests will be served by the same process.
Store persistent data in the datastore, or memcache. Webapp has a sessions framework which can help with this.
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417065%2fwhy-does-post-not-see-attribute-set-in-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Don't try and store state in classes across requests. GAE, like most web environments, runs multiple processes - potentially in multiple separate containers or even datacentres - to serve your requests. There is absolutely no guarantee that subsequent requests will be served by the same process.
Store persistent data in the datastore, or memcache. Webapp has a sessions framework which can help with this.
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
add a comment |
Don't try and store state in classes across requests. GAE, like most web environments, runs multiple processes - potentially in multiple separate containers or even datacentres - to serve your requests. There is absolutely no guarantee that subsequent requests will be served by the same process.
Store persistent data in the datastore, or memcache. Webapp has a sessions framework which can help with this.
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
add a comment |
Don't try and store state in classes across requests. GAE, like most web environments, runs multiple processes - potentially in multiple separate containers or even datacentres - to serve your requests. There is absolutely no guarantee that subsequent requests will be served by the same process.
Store persistent data in the datastore, or memcache. Webapp has a sessions framework which can help with this.
Don't try and store state in classes across requests. GAE, like most web environments, runs multiple processes - potentially in multiple separate containers or even datacentres - to serve your requests. There is absolutely no guarantee that subsequent requests will be served by the same process.
Store persistent data in the datastore, or memcache. Webapp has a sessions framework which can help with this.
answered Nov 21 '18 at 17:09
Daniel RosemanDaniel Roseman
457k42593650
457k42593650
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
add a comment |
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
I am using both datastore and sessions in my real code, but was puzzled why GAE breaks the OOP paradigm and methods do not see the class attribute.
– Stephen
Nov 21 '18 at 17:31
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
It doesn't "break the oop paradigm". Why do you think it does? Variables set on an instance within the same request will of course be visible as with any other Python code.
– Daniel Roseman
Nov 21 '18 at 17:37
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
when I run on localhost then I am using the same process, so google has deliberately changed something to make one method not see what another method did. anyway, I understand your answer and the implication to use sessions for passing non-permanent stuff.
– Stephen
Nov 21 '18 at 21:00
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
A new instance of the RequestHandler class you attach to the route is instantiated for each request, so saying "there is no guarantee subsequent requests will be served by the process" is true, but not relevant.
– Greg
Nov 21 '18 at 22:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417065%2fwhy-does-post-not-see-attribute-set-in-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The 'webapp' framework you're using here has been end-of-lifed. The successor, webapp2, has a section documenting how handlers work here - you might find it helpful: webapp2.readthedocs.io/en/latest/guide/…
– Greg
Nov 21 '18 at 22:52