can't update images

8 views
Skip to first unread message

Scheck David

unread,
Mar 27, 2019, 11:03:59 AM3/27/19
to sqlalchemy
Hi everyone,

I try to update an attribute but it appears that it doesn't save. Would you know why ? it's very strange because the print is good. but when I query again this uri_reference it finds Nonetype.

here is the command : 

```

@contextlib.contextmanager
def db_session(settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    session_maker = sessionmaker(bind=engine)
    session = session_maker()
    try:
        yield session
        session.commit()
    except Exception:
        session.rollback()
    finally:
        session.close()


def process(settings):
    """
    Command to migrate urls to a single JSON field for performance issues
    """
    with db_session(settings) as session:
        print ("====================")
        print ("SELECTING ALL IMAGES")
        print ("====================")
        for image in session.query(Image).limit(40).all():
            urls = _list_uri_references_for_data(image.image_metadata)
            urls.append(image.state.actor_uri)
            image.uri_reference = urls
            print ("{}: SAVING -> {}".format(image.name, image.uri_reference))
        print ("====================")
        print ("CLOSING SCRIPT")
        print ("====================")
```

Thanks in advance.

Scheck David

unread,
Mar 27, 2019, 11:52:49 AM3/27/19
to sqlalchemy
it's ok, it's saving but what is strange is that my query doesn't find this records:

this is my sql : 

 sql = 'SELECT ss.id, ss.name, ss.image_metadata FROM (SELECT image.id, image.image_metadata, image.name, json_array_elements(image.uri_reference)::text as uri_ref FROM image) ss WHERE ss.uri_ref = :uri ORDER BY ss.id LIMIT 5'
        result = self.session.execute(text(sql).params(uri=uri))
        return result

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
http://www.sqlalchemy.org/
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/F0WBuRrxa4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--

With kindest regards,


David SCHECK

PRESIDENT/DEVELOPER

Signature Logo Sphax Bleu-01.png


Phone: +32 4 87 86 70 12
Visit our website ! https://www.sphax.org

Scheck David

unread,
Mar 29, 2019, 6:20:50 AM3/29/19
to sqlalchemy
Ok solved it in postgresql thanks
Reply all
Reply to author
Forward
0 new messages