def get_tickets_for_milestone(env, milestone=None, field='component'):
    """Retrieve all tickets associated with the given `milestone`.
    """
    fields = TicketSystem(env).get_ticket_fields()
    if field in [f['name'] for f in fields if not f.get('custom')]:
        sql = """SELECT id, status, %s FROM ticket WHERE milestone=%%s
                 ORDER BY %s""" % (field, field)
        args = (milestone,)
    else:
        sql = """SELECT id, status, value FROM ticket
                   LEFT OUTER JOIN ticket_custom ON (id=ticket AND name=%s)
                  WHERE milestone=%s ORDER BY value"""
        args = (field, milestone)
    return [{'id': tkt_id, 'status': status, field: fieldval}
            for tkt_id, status, fieldval in env.db_query(sql, args)]
dataset/ETHPy150Open edgewall/trac/trac/ticket/roadmap.py/get_tickets_for_milestone/original