Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pythonstartup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
initialize_db()

# Make it easier to do session stuff at the command line
session = Session().session
session = Session()

if c.DEV_BOX:
admin = session.query(AdminAccount).filter(
Expand Down
4 changes: 2 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
logger = logging.getLogger('alembic.env')

# Add the model's MetaData object here for "autogenerate" support.
target_metadata = Session.BaseClass.metadata
target_metadata = uber.models.MagModel.metadata


def include_object(object, name, type_, reflected, compare_to):
"""Exclude alembic's own version tables from alembic's consideration."""
return not name.startswith('alembic_version')
return not name or not name.startswith('alembic_version')


def render_item(type_, obj, autogen_context):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Add missing columns from SQLAlchemy upgrade

Revision ID: 3d942ce689fc
Revises: 5a0e898174d4
Create Date: 2026-02-05 16:34:19.803186

"""


# revision identifiers, used by Alembic.
revision = '3d942ce689fc'
down_revision = '5a0e898174d4'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


try:
is_sqlite = op.get_context().dialect.name == 'sqlite'
except Exception:
is_sqlite = False

if is_sqlite:
op.get_context().connection.execute('PRAGMA foreign_keys=ON;')
utcnow_server_default = "(datetime('now', 'utc'))"
else:
utcnow_server_default = "timezone('utc', current_timestamp)"

def sqlite_column_reflect_listener(inspector, table, column_info):
"""Adds parenthesis around SQLite datetime defaults for utcnow."""
if column_info['default'] == "datetime('now', 'utc')":
column_info['default'] = utcnow_server_default

sqlite_reflect_kwargs = {
'listeners': [('column_reflect', sqlite_column_reflect_listener)]
}

# ===========================================================================
# HOWTO: Handle alter statements in SQLite
#
# def upgrade():
# if is_sqlite:
# with op.batch_alter_table('table_name', reflect_kwargs=sqlite_reflect_kwargs) as batch_op:
# batch_op.alter_column('column_name', type_=sa.Unicode(), server_default='', nullable=False)
# else:
# op.alter_column('table_name', 'column_name', type_=sa.Unicode(), server_default='', nullable=False)
#
# ===========================================================================


def upgrade():
op.add_column('panel_applicant', sa.Column('social_media_info', sa.String(), server_default='', nullable=False))
op.drop_column('panel_applicant', 'social_media')
op.drop_index(op.f('uq_promo_code_word_normalized_word_part_of_speech'), table_name='promo_code_word')
op.create_index('uq_promo_code_word_normalized_word_part_of_speech', 'promo_code_word', [sa.literal_column('lower(trim(word))'), 'part_of_speech'], unique=True)


def downgrade():
op.drop_index('uq_promo_code_word_normalized_word_part_of_speech', table_name='promo_code_word')
op.create_index(op.f('uq_promo_code_word_normalized_word_part_of_speech'), 'promo_code_word', [sa.literal_column('lower(TRIM(BOTH FROM word))'), 'part_of_speech'], unique=True)
op.add_column('panel_applicant', sa.Column('social_media', postgresql.JSON(astext_type=sa.Text()), server_default=sa.text("'{}'::json"), autoincrement=False, nullable=False))
op.drop_column('panel_applicant', 'social_media_info')
606 changes: 606 additions & 0 deletions alembic/versions/6902e1cceec6_relationships_overhaul.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion alembic/versions/d0c15c44a031_add_extra_donation_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def upgrade():
batch_op.add_column(sa.Column('extra_donation', sa.Integer(), server_default='0', nullable=False))
else:
# Because this column used to be in an event plugin, we check for its existence before making it
exists = conn.execute("SELECT COLUMN_NAME FROM information_schema.columns where TABLE_NAME = 'attendee' and COLUMN_NAME = 'extra_donation'").fetchall()
exists = conn.execute(sa.text("SELECT COLUMN_NAME FROM information_schema.columns where TABLE_NAME = 'attendee' and COLUMN_NAME = 'extra_donation'")).fetchall()
if not exists:
op.add_column('attendee', sa.Column('extra_donation', sa.Integer(), server_default='0', nullable=False))

Expand Down
2 changes: 1 addition & 1 deletion docs/script_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

with Session() as session:
initialize_db()
session = Session().session
session = Session()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be called? Shouldn't session already be defined and set to the session by the context manager?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, yea, this must have been an old copy-paste error.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ configobj==5.0.9
email_validator==2.2.0
fpdf2==2.8.3
geopy==2.4.1
TatSu==5.7.4
ics==0.7.2
Jinja2==3.1.6
ortools==9.14.6206
Expand All @@ -31,6 +32,7 @@ rpctools @ git+https://github.com/appliedsec/rpctools.git@4e4108c3b7b4b6c482e515
sentry-sdk==2.32.0
signnow_python_sdk==2.0.1
SQLAlchemy==2.0.46
sqlmodel==0.0.37
stripe==9.1.0
twilio==9.6.5
uszipcode==1.0.1
Expand Down
2 changes: 1 addition & 1 deletion tests/uber/models/test_badge_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.fixture
def session(request):
session = Session().session
session = Session()
request.addfinalizer(session.close)
check_ranges(session)
for badge_type, badge_name in [(c.STAFF_BADGE, 'Staff'), (c.CONTRACTOR_BADGE, 'Contractor')]:
Expand Down
20 changes: 10 additions & 10 deletions tests/uber/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_under_limit_no_price_bump(self):

def test_over_limit_price_bump_before_event(self, monkeypatch):
monkeypatch.setattr(c, 'EPOCH', localized_now() + timedelta(days=1))
session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand All @@ -57,7 +57,7 @@ def test_over_limit_price_bump_before_event(self, monkeypatch):
def test_over_limit_price_bump_during_event(self, monkeypatch):
monkeypatch.setattr(c, 'EPOCH', localized_now() - timedelta(days=1))

session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand All @@ -69,7 +69,7 @@ def test_over_limit_price_bump_during_event(self, monkeypatch):

def test_refunded_badge_price_bump_before_event(self, monkeypatch):
monkeypatch.setattr(c, 'EPOCH', localized_now() + timedelta(days=1))
session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand All @@ -81,7 +81,7 @@ def test_refunded_badge_price_bump_before_event(self, monkeypatch):

def test_refunded_badge_price_bump_during_event(self, monkeypatch):
monkeypatch.setattr(c, 'EPOCH', localized_now() - timedelta(days=1))
session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand All @@ -92,7 +92,7 @@ def test_refunded_badge_price_bump_during_event(self, monkeypatch):
assert 40 == c.get_attendee_price()

def test_invalid_badge_no_price_bump(self):
session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand All @@ -103,7 +103,7 @@ def test_invalid_badge_no_price_bump(self):
assert 40 == c.get_attendee_price()

def test_free_badge_no_price_bump(self):
session = Session().session
session = Session()
assert c.BADGES_SOLD == 0

with request_cached_context():
Expand Down Expand Up @@ -249,31 +249,31 @@ def test_dealer_reg_soft_closed_after_deadline(self, monkeypatch):
assert c.DEALER_REG_SOFT_CLOSED

def test_dealer_app(self):
session = Session().session
session = Session()
with request_cached_context():
session.add(Group(tables=1, cost=10, status=c.UNAPPROVED))
session.commit()

assert c.DEALER_APPS == 1

def test_waitlisted_dealer_not_app(self):
session = Session().session
session = Session()
with request_cached_context():
session.add(Group(tables=1, cost=10, status=c.WAITLISTED))
session.commit()

assert c.DEALER_APPS == 0

def test_free_dealer_no_app(self):
session = Session().session
session = Session()
with request_cached_context():
session.add(Group(tables=1, cost=0, auto_recalc=False, status=c.UNAPPROVED))
session.commit()

assert c.DEALER_APPS == 0

def test_not_a_dealer_no_app(self):
session = Session().session
session = Session()
with request_cached_context():
session.add(Group(tables=0, cost=10, status=c.UNAPPROVED))
session.commit()
Expand Down
2 changes: 1 addition & 1 deletion tests/uber/models/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@pytest.fixture
def session(request, monkeypatch):
session = Session().session
session = Session()
request.addfinalizer(session.close)
monkeypatch.setattr(session, 'add', Mock())
monkeypatch.setattr(session, 'delete', Mock())
Expand Down
2 changes: 1 addition & 1 deletion tests/uber/models/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_total_hours(monkeypatch):

@pytest.fixture
def session(request):
session = Session().session
session = Session()
for num in ['One', 'Two', 'Three', 'Four', 'Five', 'Six']:
setattr(session, 'job_' + num.lower(), session.job(name='Job ' + num))
for num in ['One', 'Two', 'Three', 'Four', 'Five']:
Expand Down
2 changes: 1 addition & 1 deletion tests/uber/models/test_watchlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.fixture()
def session(request):
session = Session().session
session = Session()
request.addfinalizer(session.close)
setattr(session, 'watchlist_entry', session.watch_list(first_names='Banned, Alias, Nickname', last_name='Attendee'))
return session
Expand Down
4 changes: 2 additions & 2 deletions tests/uber/test_custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_filters_allow_empty_arg(self, filter_function, test_input, expected):
([1, 30, 100, 100, 20, 12, 2], {}),
])
def test_timedelta_filter(self, timedelta_args, timedelta_kwargs):
dt = datetime.utcnow()
dt = datetime.now(UTC)
td = timedelta(*timedelta_args, **timedelta_kwargs)
expected = dt + td
assert expected == timedelta_filter(dt, *timedelta_args, **timedelta_kwargs)
Expand All @@ -49,7 +49,7 @@ def test_timedelta_filter_with_empty_date(self):
assert timedelta_filter('', 1, 3600) is None

def test_timedelta_filter_in_template(self):
dt = datetime.utcnow()
dt = datetime.now(UTC)
env = JinjaEnv.env()
template = env.from_string('{{ dt|timedelta(days=-5)|datetime("%A, %B %-e") }}')
expected = (dt + timedelta(days=-5)).strftime("%A, %B %-e")
Expand Down
Loading
Loading