From cef15864e514821b68cf4d3704b40d82b51d31f0 Mon Sep 17 00:00:00 2001
From: mishaschwartz <4380924+mishaschwartz@users.noreply.github.com>
Date: Tue, 19 Nov 2024 12:37:45 -0500
Subject: [PATCH] Run continuous integration tests when code is changed in the 
 directory as well

---
 .github/workflows/continuous-integration.yml | 3 +++
 CHANGELOG.md                                 | 1 +
 docker/pypgstac/bin/test                     | 4 ++--
 src/pypgstac/src/pypgstac/load.py            | 8 ++++----
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 57237ca7..6c6c6dc7 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -31,8 +31,10 @@ jobs:
           filters: |
             pgstac:
               - 'docker/pgstac/**'
+              - 'src/pgstac/pgstac.sql'
             pypgstac:
               - 'docker/pypgstac/**'
+              - 'src/**'
       - id: check
         run: |
           buildpg=false;
@@ -101,6 +103,7 @@ jobs:
   test:
     name: test
     needs: [changes, buildpg, buildpyrust]
+    if: ${{ needs.changes.outputs.buildpgdocker == 'true' || needs.changes.outputs.buildpyrustdocker == 'true' }}
     runs-on: ubuntu-latest
     container:
       image: ${{ needs.changes.outputs.pyrustdocker }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4a492c3..ea4405d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 - Add `open=True` in `psycopg.ConnectionPool` to avoid future behavior change
 - Switch from postgres `server_version` to `server_version_num` to get PG version (Fixes #300)
 - Allow read-only replicas work even when the context extension is enabled (Fixes #300)
+- Run continuous integration tests when code is changed in the `src` directory as well (Fixes #321)
 
 ## [v0.9.1]
 
diff --git a/docker/pypgstac/bin/test b/docker/pypgstac/bin/test
index 5e61d1bb..9eaf134f 100755
--- a/docker/pypgstac/bin/test
+++ b/docker/pypgstac/bin/test
@@ -46,10 +46,10 @@ function test_formatting(){
     cd $SRCDIR/pypgstac
 
     echo "Running ruff"
-    ruff -n python tests
+    ruff -n src tests
 
     echo "Running mypy"
-    mypy python
+    mypy src
 
     echo "Checking if there are any staged migrations."
     find $SRCDIR/pgstac/migrations | grep 'staged' && { echo "There are staged migrations in pypgstac/migrations. Please check migrations and remove staged suffix."; exit 1; }
diff --git a/src/pypgstac/src/pypgstac/load.py b/src/pypgstac/src/pypgstac/load.py
index 2e9bcc6a..68ce1525 100644
--- a/src/pypgstac/src/pypgstac/load.py
+++ b/src/pypgstac/src/pypgstac/load.py
@@ -492,12 +492,12 @@ def _partition_update(self, item: Dict[str, Any]) -> str:
                 ),
             )
             if db_rows:
-                datetime_range_min: Optional[datetime] = db_rows[0][0] or datetime.min
-                datetime_range_max: Optional[datetime] = db_rows[0][1] or datetime.max
-                end_datetime_range_min: Optional[datetime] = (
+                datetime_range_min: datetime = db_rows[0][0] or datetime.min
+                datetime_range_max: datetime = db_rows[0][1] or datetime.max
+                end_datetime_range_min: datetime = (
                     db_rows[0][2] or datetime.min
                 )
-                end_datetime_range_max: Optional[datetime] = (
+                end_datetime_range_max: datetime = (
                     db_rows[0][3] or datetime.max
                 )