Python Model.query.get(data[';id';])返回无

Python Model.query.get(data[';id';])返回无,python,flask,sqlalchemy,consumer,Python,Flask,Sqlalchemy,Consumer,我正在开发一个微服务,Django是管理员,Flask是主应用。每当我更新数据库中的模型实例时,队列最好将实例打印到控制台,而不是返回None 主烧瓶应用程序上的消费者 params = pika.URLParameters('some URL') connection = pika.BlockingConnection(params) channel = connection.channel() channel.queue_declare(queue='main') def callb

我正在开发一个微服务,Django是管理员,Flask是主应用。每当我更新数据库中的模型实例时,队列最好将实例打印到控制台,而不是返回None

主烧瓶应用程序上的消费者

params = pika.URLParameters('some URL')

connection = pika.BlockingConnection(params)

channel = connection.channel()

channel.queue_declare(queue='main')

def callback(ch, method, properties, body):
    print('Recieved in main')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product_created':
        product = Product(id=data['id'], title=data['title'], image=data['image'])

        #  Create object with SQLAlchemy
        db.session.add(product)
        db.session.commit()
        print('Product Created')

    elif properties.content_type == 'product_updated':
        product = Product.query.get(data['id'])
        
        product.title = data['title']
        product.image = data['image']
        
        db.session.commit()
        print('Product Updated')
    
    elif properties.content_type == 'product_deleted':
        product = Product.query.get(data)

        db.session.delete(product)
        db.session.commit()
        print('Product Deleted')




channel.basic_consume(queue='main', on_message_callback=callback, auto_ack=True)

print('Started Consuming')

channel.start_consuming()

channel.close()