1

After trying everything suggested here, I still can't get SQLAlchemy to display the correct results!

I've used various combinations of Nick's answer, session.commit(), flush() and expire_all(), restarted MySQL, even restarted the entire freaking server, and I still get old results from SQLAlchemy...why????

The most infuriating thing about this whole issue is that I can see from any other application, or even from a direct connection.execute() call, that the updated data is there. I just can't get it to display on the webpage!

BTW this is in a Pyramid app, not Flask, but since Pyramid is 99% Flask it shouldn't make a difference, right?

MTIA for any help on this, it's driving me nuts!!

PS: I tried to add this as an answer to the linked question, but it was deleted for not being a valid answer. So for future reference, if I just want to add something to an existing question without having to post an entirely new one, how would I go about that?

EDIT: My apologies zvone, here is my code:

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
session = DBSession()
query = session.query(Item).join(Item.tagged)

filters = []
for term in searchTerms:
    subterms = term.split(' ')
    for subterm in subterms:
        filters.append(Item.itemTitle.like('%' + subterm + '%'))
        filters.append(Tag.tagName.like('%' + subterm + '%'))

query = query.filter(or_(*filters))
matchedItems = query.all()

And to make some more sense out of it, here's the context:

  1. I'm building a basic CMS where users can upload and download items of any type (text files, images, etc.).
  2. The whole idea of this page is to allow the user to search for items that have been tagged with certain expressions. Tags are entered in the search field as a comma-delimited string of search phrases, e.g. "movies, books, photos, search term with spaces". This string is split up into its counterparts to create searchTerms, a Python list of all the terms entered into the field.
  3. You can see in the code where I'm iterating through searchTerms, splitting phrases into separate words and adding query filters for each word.
  4. The problem arises when searching for "big, theory". I know for certain that 3 users on the production site have posted Big Bang Theory episodes, but after migrating these DB records to my dev server, I only get one search result (the old amount).

Many thanks again for the help! :D

Community
  • 1
  • 1
Kenny83
  • 769
  • 12
  • 38
  • Yes, to add something relevant to an existing question, write a new question. That is the correct thing to do. – zvone Oct 15 '16 at 08:10
  • One thing is missing from the question though: your code. In order to understand what is causing the problem in your case, we have to see your code. Remove everything irrlevant from it. Leave only the part that opens the session, reads from the database and e.g. prints the value which is wrong. Confirm that such reduced code still reproduces the error and then paste it here. – zvone Oct 15 '16 at 08:13
  • 1
    "but since Pyramid is 99% Flask it shouldn't make a difference, right?" is pretty much 100% off the mark. They are **entirely** different frameworks. – Ilja Everilä Oct 15 '16 at 22:08
  • @ilja my apologies, I thought Pyramid was based upon Flask but I guess I was wrong. – Kenny83 Oct 16 '16 at 15:35
  • Quite likely you are having issues with transaction isolation and transactions not being closed when you think they are. – inklesspen Oct 16 '16 at 18:45

0 Answers0