Skip to content

Commit 5b65f25

Browse files
authored
feat: make the application tzaware
2 parents 3ad1daa + 62bee25 commit 5b65f25

203 files changed

Lines changed: 3297 additions & 1497 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ jobs:
144144
run: |
145145
echo "Running checks..."
146146
./ietf/manage.py check
147+
./ietf/manage.py migrate || true
148+
echo "USE_TZ = True" >> ./ietf/settings_local.py
147149
./ietf/manage.py migrate
148150
echo "Validating migrations..."
149151
if ! ( ietf/manage.py makemigrations --dry-run --check --verbosity 3 ) ; then

.github/workflows/ci-run-tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- 'main'
7+
- 'feat/tzaware'
78
paths:
89
- 'ietf/**'
910
- 'requirements.txt'
@@ -42,6 +43,10 @@ jobs:
4243
run: |
4344
echo "Running checks..."
4445
./ietf/manage.py check
46+
echo "Running migrations with USE_TZ=False..."
47+
./ietf/manage.py migrate || true
48+
echo "USE_TZ = True" >> ./ietf/settings_local.py
49+
echo "Running migrations with USE_TZ=True..."
4550
./ietf/manage.py migrate
4651
echo "Validating migrations..."
4752
if ! ( ietf/manage.py makemigrations --dry-run --check --verbosity 3 ) ; then

bin/add-old-drafts-from-archive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.core.validators import validate_email, ValidationError
1717
from ietf.utils.draft import PlaintextDraft
1818
from ietf.submit.utils import update_authors
19+
from ietf.utils.timezone import date_today
1920

2021
import debug # pyflakes:ignore
2122

@@ -66,9 +67,9 @@
6667
print name, rev, "Can't parse", p,":",e
6768
continue
6869
if draft.errors and draft.errors.keys()!=['draftname',]:
69-
print "Errors - could not process", name, rev, datetime.datetime.fromtimestamp(p.stat().st_mtime), draft.errors, draft.get_title().encode('utf8')
70+
print "Errors - could not process", name, rev, datetime.datetime.fromtimestamp(p.stat().st_mtime, datetime.timezone.utc), draft.errors, draft.get_title().encode('utf8')
7071
else:
71-
time = datetime.datetime.fromtimestamp(p.stat().st_mtime)
72+
time = datetime.datetime.fromtimestamp(p.stat().st_mtime, datetime.timezone.utc)
7273
if not doc:
7374
doc = Document.objects.create(name=name,
7475
time=time,
@@ -140,7 +141,7 @@ def turn_into_unicode(s):
140141
doc = doc,
141142
rev = rev,
142143
by = system,
143-
desc = "Revision added from id-archive on %s by %s"%(datetime.date.today(),sys.argv[0]),
144+
desc = "Revision added from id-archive on %s by %s"%(date_today(),sys.argv[0]),
144145
time=time,
145146
)
146147
events.append(e)

bin/check-copyright

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_first_commit(path):
162162
else:
163163
pass
164164
except OSError:
165-
rev, who, when = None, None, datetime.datetime.now()
165+
rev, who, when = None, None, datetime.datetime.now(datetime.timezone.utc)
166166
return { path: { 'rev': rev, 'who': who, 'date': when.strftime('%Y-%m-%d %H:%M:%S'), }, }
167167

168168

dev/deploy-to-container/start.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,31 @@ chmod +x ./app-create-dirs.sh
99
./app-create-dirs.sh
1010
echo "Running Datatracker checks..."
1111
./ietf/manage.py check
12-
echo "Running Datatracker migrations..."
13-
./ietf/manage.py migrate
12+
13+
# Migrate, adjusting to what the current state of the underlying database might be:
14+
WORKSPACEDIR=.
15+
if ietf/manage.py showmigrations | grep "\[ \] 0003_pause_to_change_use_tz"; then
16+
if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then
17+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = False/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
18+
else
19+
echo "USE_TZ = False" >> $WORKSPACEDIR/ietf/settings_local.py
20+
fi
21+
echo "Running Datatracker migrations with USE_TZ = False..."
22+
# This is expected to exit non-zero at the pause
23+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local || true
24+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
25+
echo "Running Datatracker migrations with USE_TZ = True..."
26+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local
27+
28+
else
29+
if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then
30+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
31+
else
32+
echo "USE_TZ = True" >> $WORKSPACEDIR/ietf/settings_local.py
33+
echo "Running Datatracker migrations..."
34+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local
35+
fi
36+
fi
37+
1438
echo "Starting Datatracker..."
1539
./ietf/manage.py runserver 0.0.0.0:8000 --settings=settings_local

dev/diff/prepare.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,24 @@ yarn legacy:build
1212
echo "Creating data directories..."
1313
chmod +x ./docker/scripts/app-create-dirs.sh
1414
./docker/scripts/app-create-dirs.sh
15+
1516
./ietf/manage.py check
16-
./ietf/manage.py migrate
17+
if ./ietf/manage.py showmigrations | grep "\[ \] 0003_pause_to_change_use_tz"; then
18+
if grep "USE_TZ" ./ietf/settings_local.py; then
19+
cat ./ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = False/' > /tmp/settings_local.py && mv /tmp/settings_local.py ./ietf/settings_local.py
20+
else
21+
echo "USE_TZ = False" >> ./ietf/settings_local.py
22+
fi
23+
# This is expected to exit non-zero at the pause
24+
/usr/local/bin/python ./ietf/manage.py migrate || true
25+
cat ./ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py ./ietf/settings_local.py
26+
/usr/local/bin/python ./ietf/manage.py migrate
27+
28+
else
29+
if grep "USE_TZ" ./ietf/settings_local.py; then
30+
cat ./ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py ./ietf/settings_local.py
31+
else
32+
echo "USE_TZ = True" >> ./ietf/settings_local.py
33+
/usr/local/bin/python ./ietf/manage.py migrate
34+
fi
35+
fi

docker/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
This project includes a devcontainer configuration which automates the setup of the development environment with all the required dependencies.
2828

2929
### Initial Setup
30-
30+
3131
1. Launch [VS Code](https://code.visualstudio.com/)
32-
2. Under the **Extensions** tab, ensure you have the **Remote - Containers** ([ms-vscode-remote.remote-containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)) extension installed. On Windows, you also need the **Remote - WSL** ([ms-vscode-remote.remote-wsl](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl)) extension to take advantage of the WSL 2 *(Windows Subsystem for Linux)* native integration.
32+
2. Under the **Extensions** tab, ensure you have the **Remote - Containers** ([ms-vscode-remote.remote-containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)) extension installed.
33+
* On Linux, note that the Snap installation of VS Code is [incompatible with this plugin](https://code.visualstudio.com/docs/devcontainers/containers#_system-requirements:~:text=snap%20package%20is%20not%20supported).
34+
* On Windows, you also need the **Remote - WSL** ([ms-vscode-remote.remote-wsl](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl)) extension to take advantage of the WSL 2 *(Windows Subsystem for Linux)* native integration.
3335
2. Open the top-level directory of the datatracker code you fetched above.
3436
3. A prompt inviting you to reopen the project in containers will appear in the bottom-right corner. Click the **Reopen in Container** button. If you missed the prompt, you can press `F1`, start typing `reopen in container` task and launch it.
3537
4. VS Code will relaunch in the dev environment and create the containers automatically.
@@ -44,8 +46,8 @@ You can also open the datatracker project folder and click the **Reopen in conta
4446
### Usage
4547

4648
- Under the **Run and Debug** tab, you can run the server with the debugger attached using **Run Server** (F5). Once the server is ready to accept connections, you'll be prompted to open in a browser. You can also open [http://localhost:8000](http://localhost:8000) in a browser.
47-
48-
> An alternate profile **Run Server with Debug Toolbar** is also available from the dropdown menu, which displays various tools
49+
50+
> An alternate profile **Run Server with Debug Toolbar** is also available from the dropdown menu, which displays various tools
4951
on top of the webpage. However, note that this configuration has a significant performance impact.
5052
5153
To add a **Breakpoint**, simply click to the left of the line gutter you wish to stop at. You can also add **Conditional Breakpoints** and **Logpoint** by right-clicking at the same location.
@@ -88,7 +90,7 @@ You can also open the datatracker project folder and click the **Reopen in conta
8890
cd docker
8991
./run
9092
```
91-
93+
9294
> Note that you can pass the `-r` flag to `./run` to force a rebuild of the containers. This is useful if you switched branches and that the existing containers still contain configurations from the old branch. You should also use this if you don't regularly keep up with main and your containers reflect a much older version of the branch.
9395

9496
On Windows *(using Powershell)*:
@@ -157,7 +159,7 @@ cd docker
157159
On Windows:
158160
```sh
159161
docker compose down -v --rmi all
160-
docker image prune
162+
docker image prune
161163
```
162164

163165
### Accessing MariaDB Port

docker/scripts/app-init.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,28 @@ echo "Starting memcached..."
100100

101101
echo "Running initial checks..."
102102
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py check --settings=settings_local
103-
# /usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local
103+
104+
# Migrate, adjusting to what the current state of the underlying database might be:
105+
106+
if ietf/manage.py showmigrations | grep "\[ \] 0003_pause_to_change_use_tz"; then
107+
if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then
108+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = False/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
109+
else
110+
echo "USE_TZ = False" >> $WORKSPACEDIR/ietf/settings_local.py
111+
fi
112+
# This is expected to exit non-zero at the pause
113+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local || true
114+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
115+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local
116+
117+
else
118+
if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then
119+
cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
120+
else
121+
echo "USE_TZ = True" >> $WORKSPACEDIR/ietf/settings_local.py
122+
/usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local
123+
fi
124+
fi
104125

105126
echo "-----------------------------------------------------------------"
106127
echo "Done!"

ietf/api/management/commands/makeresources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
import os
6-
import datetime
76
import collections
87
import io
98

@@ -14,6 +13,7 @@
1413
from django.core.management.base import AppCommand
1514
from django.db import models
1615
from django.template import Template, Context
16+
from django.utils import timezone
1717

1818
from tastypie.resources import ModelResource
1919

@@ -89,7 +89,7 @@ def handle_app_config(self, app, **options):
8989
info = dict(
9090
app=app.name,
9191
app_label=app.label,
92-
date=datetime.datetime.now()
92+
date=timezone.now()
9393
)
9494
new_models = {}
9595
for model, rclass_name in missing_resources:

ietf/api/tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from ietf.person.models import PersonalApiKey
3333
from ietf.stats.models import MeetingRegistration
3434
from ietf.utils.mail import outbox, get_payload_text
35+
from ietf.utils.models import DumpInfo
3536
from ietf.utils.test_utils import TestCase, login_testing_unauthorized
3637

3738
OMITTED_APPS = (
@@ -508,10 +509,17 @@ def test_api_new_meeting_registration(self):
508509
self.assertEqual(set(missing_fields), set(drop_fields))
509510

510511
def test_api_version(self):
512+
DumpInfo.objects.create(date=timezone.datetime(2022,8,31,7,10,1,tzinfo=timezone.utc), host='testapi.example.com',tz='UTC')
511513
url = urlreverse('ietf.api.views.version')
512514
r = self.client.get(url)
513515
data = r.json()
514516
self.assertEqual(data['version'], ietf.__version__+ietf.__patch__)
517+
self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 +0000")
518+
DumpInfo.objects.update(tz='PST8PDT')
519+
r = self.client.get(url)
520+
data = r.json()
521+
self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 -0700")
522+
515523

516524
def test_api_appauth(self):
517525
url = urlreverse('ietf.api.views.app_auth')

0 commit comments

Comments
 (0)