Skip to content

Commit 60f4a01

Browse files
committed
Add a default value for Release.published field.
1 parent 5846e30 commit 60f4a01

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

tests/common/db/packaging.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class Meta:
123123
lambda o: hashlib.blake2b(o.filename.encode("utf8"), digest_size=32).hexdigest()
124124
)
125125
upload_time = factory.Faker(
126-
"date_time_between_dates", datetime_start=datetime.datetime(2008, 1, 1)
126+
"date_time_between_dates",
127+
datetime_start=datetime.datetime(2008, 1, 1),
127128
)
128129
path = factory.LazyAttribute(
129130
lambda o: "/".join(

tests/unit/packaging/test_views.py

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
12+
from datetime import datetime
1213

1314
import pretend
1415
import pytest
@@ -323,6 +324,15 @@ def test_long_singleline_license(self, db_request):
323324
"characters, it's really so lo..."
324325
)
325326

327+
def test_created_with_published(self, db_request):
328+
release = ReleaseFactory.create()
329+
assert release.published > datetime(year=2008, month=1, day=1)
330+
331+
def test_without_published_date(self, db_request):
332+
release = ReleaseFactory.create(published=None)
333+
db_request.db.flush()
334+
assert release.published is None
335+
326336

327337
class TestReportMalwareButton:
328338
def test_report_malware_button(self):

warehouse/forklift/legacy.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import zipfile
2020

2121
from cgi import FieldStorage
22+
from datetime import datetime
2223

2324
import packaging.requirements
2425
import packaging.specifiers
@@ -902,6 +903,7 @@ def file_upload(request):
902903
},
903904
uploader=request.user if request.user else None,
904905
uploaded_via=request.user_agent,
906+
published=datetime.now(),
905907
)
906908
request.db.add(release)
907909
is_new_release = True

warehouse/migrations/versions/3e7bf3217166_add_published_in_release.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
def upgrade():
2929
op.add_column(
3030
"releases",
31-
sa.Column(
32-
"published", sa.DateTime(), server_default=sa.text("now()"), nullable=True
33-
),
31+
sa.Column("published", sa.DateTime(), nullable=True),
3432
)
3533

3634
op.execute(

warehouse/packaging/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# limitations under the License.
1212
from __future__ import annotations
1313

14+
import datetime
1415
import enum
1516
import typing
1617

@@ -612,7 +613,7 @@ def __table_args__(cls): # noqa
612613
_pypi_ordering: Mapped[int | None]
613614
requires_python: Mapped[str | None] = mapped_column(Text)
614615
created: Mapped[datetime_now] = mapped_column()
615-
published: Mapped[datetime_now | None]
616+
published: Mapped[datetime.datetime | None]
616617

617618
description_id: Mapped[UUID] = mapped_column(
618619
ForeignKey("release_descriptions.id", onupdate="CASCADE", ondelete="CASCADE"),

0 commit comments

Comments
 (0)