Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3244158
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:31:04+00:00 2026-05-17T18:31:04+00:00

For a mock web service I wrote a little Django app, that serves as

  • 0

For a mock web service I wrote a little Django app, that serves as a web API, which my android application queries. When I make requests tp the API, I am also able to hand over an offset and limit to only have the really necessary data transmitted. Anyway, I ran into the problem, that Django gives me different results for the same query to the API. It seems as if the results are returned round robin.

This is the Django code that will be run:

def getMetaForCategory(request, offset, limit):
    if request.method == "GET":
        result = { "meta_information": [] }

        categoryIDs = request.GET.getlist("category_ids[]")

        categorySet = set(toInt(categoryIDs))
        categories = Category.objects.filter(id__in = categoryIDs)

        metaSet = set([])

        for category in categories:
            metaSet = metaSet | set(category.meta_information.all())

        metaList = list(metaSet)
        metaList.sort()

        for meta in metaList[int(offset):int(limit)]: 
            relatedCategoryIDs = getIDs(meta.category_set.all())

            item = {
                "_id": meta.id,
                "name": meta.name,
                "type": meta.type,
                "categories": list(categorySet & set(relatedCategoryIDs))
            }

            result['meta_information'].append(item)

        return HttpResponse(content = simplejson.dumps(result), mimetype = "application/json")
    else:
        return HttpResponse(status = 403)

What happens is the following: If all MetaInformation objects would be Foo, Bar, Baz and Blib and I would set the limit to 0:2, then I would get [Foo, Bar] with the first request and with the exact same request the method would return [Baz, Blib] when I run it for the second time.

Does anyone see what I am doing wrong here? Or is it the Django cache that somehow gets into my way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:31:04+00:00Added an answer on May 17, 2026 at 6:31 pm

    I think the difficulty is that you are using a set to store your objects, and slicing that – and sets have no ordering (they are like dictionaries in that way). So, the results from your query are in fact indeterminate.

    There are various implementations of ordered sets around – you could look into using one of them. However, I must say that I think you are doing a lot of unnecessary and expensive unique-ifying and sorting in Python, when most of this could be done directly by the database. For instance, you seem to be trying to get the unique list of Metas that are related to the categories you pass. Well, this could be done in a single ORM query:

    meta_list = MetaInformation.objects.filter(category__id__in=categoryIDs)
    

    and you could then drop the set, looping and sorting commands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Python module that wraps out a certain web service API. It's
I have a python (django) web application. It uses an external web service (Facebook
How do you mock a SMS gateway? To test a web service that sends
I have an application that sends messages to an external web service. I build
We use SoapUI to mock web services to test our application (APP) before we
Can you do mock page requests with NUnit with webforms? what about web service
I am working on a web application, whose mock-up page can now be found
I'm writing some code that calls a web service, reads back the response and
I have a web application that stores a lot of user generated files. Currently
My application I have an application design that looks like this: web application layer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.