| 14 | |
| 15 | |
| 16 | class EnvironmentFeatureVersionManager(SoftDeleteManager): # type: ignore[misc] |
| 17 | def get_latest_versions_by_environment_id(self, environment_id: int) -> RawQuerySet: # type: ignore[type-arg] |
| 18 | """ |
| 19 | Get the latest EnvironmentFeatureVersion objects for a given environment. |
| 20 | """ |
| 21 | return self._get_latest_versions(environment_id=environment_id) |
| 22 | |
| 23 | def get_latest_versions_by_environment_api_key( |
| 24 | self, environment_api_key: str |
| 25 | ) -> RawQuerySet: # type: ignore[type-arg] |
| 26 | """ |
| 27 | Get the latest EnvironmentFeatureVersion objects for a given environment. |
| 28 | """ |
| 29 | return self._get_latest_versions(environment_api_key=environment_api_key) |
| 30 | |
| 31 | def get_latest_versions_as_queryset( |
| 32 | self, environment_id: int |
| 33 | ) -> QuerySet["EnvironmentFeatureVersion"]: |
| 34 | """ |
| 35 | Get the latest EnvironmentFeatureVersion objects for a given environment |
| 36 | as a concrete QuerySet. |
| 37 | |
| 38 | Note that it is often required to return the proper QuerySet to carry out |
| 39 | operations on the ORM object. |
| 40 | """ |
| 41 | return self.filter( # type: ignore[no-any-return] |
| 42 | uuid__in=[ |
| 43 | efv.uuid |
| 44 | for efv in self._get_latest_versions(environment_id=environment_id) |
| 45 | ] |
| 46 | ) |
| 47 | |
| 48 | def _get_latest_versions( |
| 49 | self, |
| 50 | environment_id: int = None, # type: ignore[assignment] |
| 51 | environment_api_key: str = None, # type: ignore[assignment] |
| 52 | ) -> RawQuerySet: # type: ignore[type-arg] |
| 53 | assert (environment_id or environment_api_key) and not ( |
| 54 | environment_id and environment_api_key |
| 55 | ), "Must provide exactly one of environment_id or environment_api_key" |
| 56 | |
| 57 | return self.raw( # type: ignore[no-any-return] |
| 58 | get_latest_versions_sql, |
| 59 | params={ |
| 60 | "environment_id": environment_id, |
| 61 | "api_key": environment_api_key, |
| 62 | # TODO: |
| 63 | # It seems as though there is a timezone issue when using postgres's |
| 64 | # built in now() function, so we pass in the current time from python. |
| 65 | # Using <= now() in the SQL query returns incorrect results. |
| 66 | # More investigation is needed here to understand the cause. |
| 67 | "live_from_before": timezone.now().isoformat(), |
| 68 | }, |
| 69 | ) |
no outgoing calls
no test coverage detected
searching dependent graphs…