Refactor Query.get() => Session.get() per SQLAlchemy 1.4

This commit is contained in:
Lance Edgar 2023-02-11 22:06:43 -06:00
parent 6696973868
commit 0b5930a511
2 changed files with 16 additions and 16 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -187,7 +187,7 @@ class CoreMemberBatchHandler(BatchHandler):
row.status_text = "row has no card number" row.status_text = "row has no card number"
return return
core_member = self.core_session.query(corepos.MemberInfo).get(row.card_number) core_member = self.core_session.get(corepos.MemberInfo, row.card_number)
if not core_member: if not core_member:
row.status_code = row.STATUS_MEMBER_NOT_FOUND row.status_code = row.STATUS_MEMBER_NOT_FOUND
row.status_text = "matching record not found in CORE" row.status_text = "matching record not found in CORE"
@ -250,7 +250,7 @@ class CoreMemberBatchHandler(BatchHandler):
fields = batch.get_param('fields') fields = batch.get_param('fields')
def update(row, i): def update(row, i):
core_member = core_session.query(corepos.MemberInfo).get(row.card_number) core_member = core_session.get(corepos.MemberInfo, row.card_number)
if not core_member: if not core_member:
log.warning("CORE member not found for row %s with card number: %s", log.warning("CORE member not found for row %s with card number: %s",
row.uuid, row.card_number) row.uuid, row.card_number)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -241,37 +241,37 @@ class FromRattailToCore(DataSyncImportConsumer):
def get_customers(self, session, change): def get_customers(self, session, change):
if change.payload_type == 'Customer': if change.payload_type == 'Customer':
customer = session.query(model.Customer).get(change.payload_key) customer = session.get(model.Customer, change.payload_key)
if customer: if customer:
return [customer] return [customer]
if change.payload_type == 'CustomerPerson': if change.payload_type == 'CustomerPerson':
cp = session.query(model.CustomerPerson).get(change.payload_key) cp = session.get(model.CustomerPerson, change.payload_key)
if cp: if cp:
return [cp.customer] return [cp.customer]
if change.payload_type == 'Person': if change.payload_type == 'Person':
person = session.query(model.Person).get(change.payload_key) person = session.get(model.Person, change.payload_key)
if person: if person:
return person.customers return person.customers
if change.payload_type == 'CustomerMailingAddress': if change.payload_type == 'CustomerMailingAddress':
address = session.query(model.CustomerMailingAddress).get(change.payload_key) address = session.get(model.CustomerMailingAddress, change.payload_key)
if address: if address:
return [address.customer] return [address.customer]
if change.payload_type == 'PersonPhoneNumber': if change.payload_type == 'PersonPhoneNumber':
phone = session.query(model.PersonPhoneNumber).get(change.payload_key) phone = session.get(model.PersonPhoneNumber, change.payload_key)
if phone: if phone:
return phone.person.customers return phone.person.customers
if change.payload_type == 'PersonEmailAddress': if change.payload_type == 'PersonEmailAddress':
email = session.query(model.PersonEmailAddress).get(change.payload_key) email = session.get(model.PersonEmailAddress, change.payload_key)
if email: if email:
return email.person.customers return email.person.customers
if change.payload_type == 'Member': if change.payload_type == 'Member':
member = session.query(model.Member).get(change.payload_key) member = session.get(model.Member, change.payload_key)
if member: if member:
return [member.customer] return [member.customer]
@ -280,24 +280,24 @@ class FromRattailToCore(DataSyncImportConsumer):
def get_vendor(self, session, change): def get_vendor(self, session, change):
if change.payload_type == 'Vendor': if change.payload_type == 'Vendor':
return session.query(model.Vendor).get(change.payload_key) return session.get(model.Vendor, change.payload_key)
if change.payload_type == 'VendorPhoneNumber': if change.payload_type == 'VendorPhoneNumber':
phone = session.query(model.VendorPhoneNumber).get(change.payload_key) phone = session.get(model.VendorPhoneNumber, change.payload_key)
if phone: if phone:
return phone.vendor return phone.vendor
if change.payload_type == 'VendorEmailAddress': if change.payload_type == 'VendorEmailAddress':
email = session.query(model.VendorEmailAddress).get(change.payload_key) email = session.get(model.VendorEmailAddress, change.payload_key)
if email: if email:
return email.vendor return email.vendor
def get_product(self, session, change): def get_product(self, session, change):
if change.payload_type == 'Product': if change.payload_type == 'Product':
return session.query(model.Product).get(change.payload_key) return session.get(model.Product, change.payload_key)
if change.payload_type == 'ProductPrice': if change.payload_type == 'ProductPrice':
price = session.query(model.ProductPrice).get(change.payload_key) price = session.get(model.ProductPrice, change.payload_key)
if price: if price:
return price.product return price.product