Skip to content

Cron job for marking event invoices due is wrong #6494

@iamareebjamal

Description

@iamareebjamal

PR #6166 is wrong. The query fails in every case

def event_invoices_mark_due():
from app import current_app as app
with app.app_context():
db.session.query(EventInvoice).\
filter(EventInvoice.status == 'upcoming',
EventInvoice.event.ends_at >= datetime.datetime.now(),
(EventInvoice.created_at + datetime.timedelta(days=30) <=
datetime.datetime.now())).\
update({'status': 'due'})
db.session.commit()

This line is not valid SQLAlchemy syntax:

EventInvoice.event.ends_at >= datetime.datetime.now(),

Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with EventInvoice.event has an attribute 'ends_at'

It should be db.session.query(EventInvoice).join(Event).filter(EventInvoice.status == 'upcoming', Event.ends_at >= datetime.datetime.now()).all()

Each run of this task is failing

Fix it and write tests to ensure it is working

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions