coralv coralv - 1 month ago 7
Python Question

Endpoint returns values in a different order on deployed server

I have an endpoint that returns a value which is basically 10 rows of strings, represented in my database by this class:

class BoardForm(messages.Message):
"""Used to show a board state"""
row_0 = messages.StringField(1)
row_1 = messages.StringField(2)
row_2 = messages.StringField(3)
row_3 = messages.StringField(4)
row_4 = messages.StringField(5)
row_5 = messages.StringField(6)
row_6 = messages.StringField(7)
row_7 = messages.StringField(8)
row_8 = messages.StringField(9)
row_9 = messages.StringField(10)


On my development server, when I use this endpoint, it neatly returns all 10 rows in exactly the order seen above. However, having deployed the app and tested the endpoint on the live server (with no change to the code), the order of my rows is different. The live endpoint also returns data for
"kind"
and
"etag"
, which is not on the dev server, and I mention because it's the only other difference I can see.

I was able to create a work-around that displays the proper order by using a different class:

class StringMessages(messages.Message):
"""Outbound (multiple) string message"""
items = messages.StringField(1, repeated=True)


I just put each row into this class, creating a list, and return that value instead (and obviously change the endpoint's
response_message
, too).

However, I am really wondering why the order would suddenly change on the deployed server. It didn't appear to be random, because repeated attempts to use the endpoint returned the same order each time (something like 4, 5, 0, 1, 2, 3, 6, 7, 8, 9 or so). I can live with my work around, but I'd rather not use it if there's a better way I can fix this. If I can gain a better understanding of GAE, that would also be good.

Answer

Not seeing how you are displaying the output. There is no "ordering" to variables. How about returning a list, which does have order:

class BoardForm(messages.Message):
    """Used to show a board state"""
    row_list = [messages.StringField(i) for i in range(1,11)]
Comments