From c03119acb267d1c0a0a64fc3266b2f4b93a9b8d7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 21 Feb 2023 18:15:27 -0600 Subject: [PATCH] Tweak ORM relationship backrefs per SA 2.0 warnings --- rattail_mailchimp/db/model.py | 10 ++++++++-- rattail_mailchimp/importing/mailchimp.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rattail_mailchimp/db/model.py b/rattail_mailchimp/db/model.py index e25b574..181cf19 100644 --- a/rattail_mailchimp/db/model.py +++ b/rattail_mailchimp/db/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -45,6 +45,11 @@ class MailChimpList(model.Base): date_created = sa.Column(sa.DateTime(), nullable=True) + members = orm.relationship('MailChimpListMember', + back_populates='list', + # nb. this is to satisfy SA 2.0 + cascade_backrefs=False) + def __str__(self): return self.name or "" @@ -62,7 +67,8 @@ class MailChimpListMember(model.Base): uuid = model.uuid_column() list_uuid = sa.Column(sa.String(length=32), nullable=False) - list = orm.relationship(MailChimpList, backref='members') + list = orm.relationship(MailChimpList, + back_populates='members') id = sa.Column(sa.String(length=32), nullable=True) diff --git a/rattail_mailchimp/importing/mailchimp.py b/rattail_mailchimp/importing/mailchimp.py index 61d5af4..eeba131 100644 --- a/rattail_mailchimp/importing/mailchimp.py +++ b/rattail_mailchimp/importing/mailchimp.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -130,10 +130,20 @@ class MailChimpListMemberImporter(FromMailChimp, mailchimp_importing.model.MailC def get_all_members(self, list_id): members = [] + # cf. https://mailchimp.com/developer/marketing/api/list-members/list-members-info/ result = self.mailchimp.lists.members.all(list_id, get_all=True, + # TODO: maybe should try this instead of # the default which seems to be 500 # count=1000 + + # TODO: this testing chunk left here for + # reference; it can be handy to filter + # results etc. for test runs + # count=500, + # # since_last_changed=datetime.date(2023, 1, 1), + # sort_field='last_changed', + # sort_dir='DESC', ) members.extend(result['members']) return members