-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try again with simpler strp directive (refs #195)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 3.1.14 on 2024-12-29 19:13 | ||
|
||
from django.db import migrations | ||
from datetime import datetime | ||
|
||
import sentry_sdk | ||
|
||
|
||
def migrate_dates(apps, schema_editor): | ||
Market = apps.get_model("ddcz", "Market") | ||
|
||
for market in Market.objects.all(): | ||
if not market.published_varchar: | ||
sentry_sdk.capture_message( | ||
"Market entry without date", | ||
level="error", | ||
extras={ | ||
"market_id": market.id, | ||
"invalid_date": market.published_varchar, | ||
}, | ||
) | ||
|
||
try: | ||
parsed_date = datetime.strptime(market.published_varchar, "%d. %m. %Y") | ||
except ValueError: | ||
sentry_sdk.capture_message( | ||
"Failed to parse date in Market record", | ||
level="error", | ||
extras={ | ||
"market_id": market.id, | ||
"invalid_date": market.published_varchar, | ||
}, | ||
) | ||
continue | ||
|
||
market.created = parsed_date | ||
market.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("ddcz", "0005_market_dates_20241229_1747"), | ||
] | ||
|
||
operations = [migrations.RunPython(migrate_dates)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters