Skip to content

Commit

Permalink
Fix conflicts and merge branch 'feat/add_mypy_type_checking' of githu…
Browse files Browse the repository at this point in the history
…b.com:Flagsmith/flagsmith into feat/add_mypy_type_checking
  • Loading branch information
zachaysan committed Dec 17, 2024
2 parents c9b44d4 + c3e7907 commit fd7574c
Show file tree
Hide file tree
Showing 27 changed files with 3,164 additions and 1,384 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
args: [--config, api/.flake8]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: check-json
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.156.1"
".": "2.157.1"
}
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Changelog

## [2.157.1](https://github.com/Flagsmith/flagsmith/compare/v2.157.0...v2.157.1) (2024-12-16)


### Bug Fixes

* description state management in EnvironmentSettingsPage ([#4917](https://github.com/Flagsmith/flagsmith/issues/4917)) ([0223227](https://github.com/Flagsmith/flagsmith/commit/02232278a1309a1b04bbe5ea03ed8019b0eec849))
* Numbers such as 1e100 cannot be retrieved from DynamoDB ([#4916](https://github.com/Flagsmith/flagsmith/issues/4916)) ([5d02ab1](https://github.com/Flagsmith/flagsmith/commit/5d02ab17cda6854d17933d0eff5a835ad2ea99ea))
* Preserve Page number in URL at AuditLogs page ([#4913](https://github.com/Flagsmith/flagsmith/issues/4913)) ([6cd6cb8](https://github.com/Flagsmith/flagsmith/commit/6cd6cb866af2ec17357b13a51e9fad56af743446))
* Set project change requests url ([#4920](https://github.com/Flagsmith/flagsmith/issues/4920)) ([e94e5c6](https://github.com/Flagsmith/flagsmith/commit/e94e5c6064c4b0df1a4cd09ddb9a0b8d30c75612))

## [2.157.0](https://github.com/Flagsmith/flagsmith/compare/v2.156.2...v2.157.0) (2024-12-10)


### Features

* Heal all identities with blank traits ([#4908](https://github.com/Flagsmith/flagsmith/issues/4908)) ([5405cc5](https://github.com/Flagsmith/flagsmith/commit/5405cc59b4e49a8936a278439c018072fcdc7df4))


### Bug Fixes

* **chargebee:** ensure that missing api calls are handled correctly ([#4901](https://github.com/Flagsmith/flagsmith/issues/4901)) ([38b4300](https://github.com/Flagsmith/flagsmith/commit/38b43004d139278a1cadc4935c5b36ab9c1cf360))
* Relax Hubspot cookie tracking ([#4905](https://github.com/Flagsmith/flagsmith/issues/4905)) ([4f20e5a](https://github.com/Flagsmith/flagsmith/commit/4f20e5a551a6d2f70329d4851188f5ebedd55f4b))
* Restore `make docker-up` ([#4907](https://github.com/Flagsmith/flagsmith/issues/4907)) ([f97c56f](https://github.com/Flagsmith/flagsmith/commit/f97c56fd79703212354d8dbbb6a7e6ca438e78a3))

## [2.156.2](https://github.com/Flagsmith/flagsmith/compare/v2.156.1...v2.156.2) (2024-12-10)


### Bug Fixes

* anchor button height ([#4891](https://github.com/Flagsmith/flagsmith/issues/4891)) ([7048c4c](https://github.com/Flagsmith/flagsmith/commit/7048c4c213ed60077aa85c30812d03544b10327a))
* audit log integrations for versioned environments ([#4876](https://github.com/Flagsmith/flagsmith/issues/4876)) ([486bcd1](https://github.com/Flagsmith/flagsmith/commit/486bcd1d2fc6a360f002183027186d70798b4f06))
* **pre-commit:** refactor prettier hook ([#4902](https://github.com/Flagsmith/flagsmith/issues/4902)) ([cbecde7](https://github.com/Flagsmith/flagsmith/commit/cbecde7cb53fd0865807f947de04f99407eacdaf))

## [2.156.1](https://github.com/Flagsmith/flagsmith/compare/v2.156.0...v2.156.1) (2024-12-04)


Expand Down
2 changes: 1 addition & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

DOCKER_TAG ?= flagsmith/flagsmith-api:local

COMPOSE_FILE ?= ../docker/db.yml
COMPOSE_FILE ?= ../docker/api/docker-compose.local.yml
COMPOSE_PROJECT_NAME ?= flagsmith

DOTENV_OVERRIDE_FILE ?= .env
Expand Down
65 changes: 65 additions & 0 deletions api/edge_api/management/commands/ensure_identity_traits_blanks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import Any

from django.core.management import BaseCommand
from structlog import get_logger
from structlog.stdlib import BoundLogger

from environments.dynamodb import DynamoIdentityWrapper

identity_wrapper = DynamoIdentityWrapper()


LOG_COUNT_EVERY = 100_000


class Command(BaseCommand):
def handle(self, *args: Any, **options: Any) -> None:
total_count = identity_wrapper.table.item_count
scanned_count = 0
fixed_count = 0

log: BoundLogger = get_logger(total_count=total_count)
log.info("started")

for identity_document in identity_wrapper.query_get_all_items():
should_write_identity_document = False

if identity_traits_data := identity_document.get("identity_traits"):
blank_traits = (
trait_data
for trait_data in identity_traits_data
if "trait_value" not in trait_data
)
for trait_data in blank_traits:
should_write_identity_document = True
trait_data["trait_value"] = ""

scanned_count += 1
scanned_percentage = scanned_count / total_count * 100

if should_write_identity_document:
identity_wrapper.put_item(identity_document)
fixed_count += 1

log.info(
"identity-fixed",
identity_uuid=identity_document["identity_uuid"],
scanned_count=scanned_count,
scanned_percentage=scanned_percentage,
fixed_count=fixed_count,
)

if not (scanned_count % LOG_COUNT_EVERY):
log.info(
"in-progress",
scanned_count=scanned_count,
scanned_percentage=scanned_percentage,
fixed_count=fixed_count,
)

log.info(
"finished",
scanned_count=scanned_count,
scanned_percentage=scanned_percentage,
fixed_count=fixed_count,
)
17 changes: 15 additions & 2 deletions api/environments/dynamodb/wrappers/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import typing
from decimal import Context
from functools import partial

import boto3
import boto3.dynamodb.types
from botocore.config import Config

if typing.TYPE_CHECKING:
from mypy_boto3_dynamodb.service_resource import Table


# Avoid `decimal.Rounded` when reading large numbers
# See https://github.com/boto/boto3/issues/2500
boto3.dynamodb.types.DYNAMODB_CONTEXT = Context(prec=100)


class BaseDynamoWrapper:
table_name: str = None

Expand All @@ -33,13 +41,18 @@ def is_enabled(self) -> bool:
return self.table is not None

def query_get_all_items(self, **kwargs: dict) -> typing.Generator[dict, None, None]:
if kwargs:
response_getter = partial(self.table.query, **kwargs)
else:
response_getter = partial(self.table.scan)

while True:
query_response = self.table.query(**kwargs)
query_response = response_getter()
for item in query_response["Items"]:
yield item

last_evaluated_key = query_response.get("LastEvaluatedKey")
if not last_evaluated_key:
break

kwargs["ExclusiveStartKey"] = last_evaluated_key
response_getter.keywords["ExclusiveStartKey"] = last_evaluated_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.17 on 2024-12-16 16:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("workflows_core", "0011_add_project_to_change_requests"),
]

operations = [
migrations.AlterModelOptions(
name="changerequest",
options={"ordering": ("id",)},
),
]
6 changes: 5 additions & 1 deletion api/features/workflows/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class ChangeRequest(

ignore_conflicts = models.BooleanField(default=False)

class Meta:
# Explicit ordering to prevent pagination warnings.
ordering = ("id",)

def approve(self, user: "FFAdminUser"):
if user.id == self.user_id:
raise CannotApproveOwnChangeRequest(
Expand Down Expand Up @@ -277,7 +281,7 @@ def url(self):
url += f"/project/{self.environment.project_id}"
url += f"/environment/{self.environment.api_key}"
else:
url += f"/projects/{self.project_id}"
url += f"/project/{self.project_id}"
url += f"/change-requests/{self.id}"
return url

Expand Down
18 changes: 13 additions & 5 deletions api/integrations/lead_tracking/hubspot/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ def register_hubspot_tracker(request: Request) -> None:
hubspot_cookie = request.data.get(HUBSPOT_COOKIE_NAME)

if not hubspot_cookie:
logger.info(f"Request did not included Hubspot data for user {request.user.id}")
return

if (
HubspotTracker.objects.filter(hubspot_cookie=hubspot_cookie)
.exclude(user=request.user)
.exists()
):
logger.info(
f"Request did not included Hubspot data for user {request.user.email}"
f"HubspotTracker could not be created for user {request.user.id}"
f" due to cookie conflict with cookie {hubspot_cookie}"
)
return

logger.info(
f"Creating HubspotTracker instance for user {request.user.email} with cookie {hubspot_cookie}"
)

HubspotTracker.objects.update_or_create(
user=request.user,
defaults={
"hubspot_cookie": hubspot_cookie,
},
)
logger.info(
f"Created HubspotTracker instance for user {request.user.id} with cookie {hubspot_cookie}"
)
2 changes: 1 addition & 1 deletion api/organisations/subscriptions/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BaseSubscriptionMetadata:
def __init__(
self,
seats: int = 0,
api_calls: None | int = None,
api_calls: int = 0,
projects: None | int = None,
chargebee_email: None | str = None,
audit_log_visibility_days: int | None = 0,
Expand Down
Loading

0 comments on commit fd7574c

Please sign in to comment.