Skip to content

Commit 376604e

Browse files
authored
chore: suppress warnings from baserow commands logs (baserow#4502)
* Remove warnings from baserow commands logs * Address feedback
1 parent e25988e commit 376604e

File tree

9 files changed

+81
-39
lines changed

9 files changed

+81
-39
lines changed

backend/src/baserow/api/workspaces/users/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def get_email(self, object):
4646

4747
def get_two_factor_auth(self, object):
4848
try:
49-
provider = object.user.two_factor_auth_providers.all()[0]
50-
except IndexError:
49+
provider = object.user.two_factor_auth_provider
50+
except User.two_factor_auth_provider.RelatedObjectDoesNotExist:
5151
provider = None
5252

5353
return TwoFactorAuthSerializer(provider).data

backend/src/baserow/api/workspaces/users/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get(self, request, workspace_id, query_params):
131131
.select_related("workspace", "user", "user__profile")
132132
.prefetch_related(
133133
Prefetch(
134-
"user__two_factor_auth_providers",
134+
"user__two_factor_auth_provider",
135135
queryset=specific_queryset(
136136
TwoFactorAuthProviderModel.objects.all()
137137
),

backend/src/baserow/config/asgi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
from channels.routing import ProtocolTypeRouter, URLRouter
66

7-
from baserow.config.helpers import ConcurrencyLimiterASGI, check_lazy_loaded_libraries
7+
from baserow.config.helpers import (
8+
ConcurrencyLimiterASGI,
9+
check_lazy_loaded_libraries,
10+
log_env_warnings,
11+
)
812
from baserow.core.mcp import get_baserow_mcp_server
913
from baserow.core.telemetry.telemetry import setup_logging, setup_telemetry
1014
from baserow.ws.routers import websocket_router
@@ -22,6 +26,9 @@
2226
# This runs after Django is fully loaded, so it catches imports from all apps.
2327
check_lazy_loaded_libraries()
2428

29+
# Finally log any warnings about the environment variables that can help debug issues.
30+
log_env_warnings()
31+
2532
application = ProtocolTypeRouter(
2633
{
2734
"http": ConcurrencyLimiterASGI(

backend/src/baserow/config/helpers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os
23
import sys
34

45
from django.conf import settings
@@ -75,3 +76,37 @@ def __init__(self, app, max_concurrency: int | None = None):
7576
async def __call__(self, scope, receive, send):
7677
async with self.semaphore:
7778
await self.app(scope, receive, send)
79+
80+
81+
def log_env_warnings():
82+
from django.conf import settings
83+
84+
if settings.BASEROW_PUBLIC_URL:
85+
if settings.BASEROW_PUBLIC_URL.startswith("http://localhost"):
86+
logger.warning(
87+
"WARNING: Baserow is configured to use a BASEROW_PUBLIC_URL of "
88+
f"{settings.BASEROW_PUBLIC_URL}. If you attempt to access Baserow on "
89+
"any other hostname requests to the backend will fail as they will be "
90+
"from an unknown host. "
91+
"Please set BASEROW_PUBLIC_URL if you will be accessing Baserow "
92+
f"from any other URL then {settings.BASEROW_PUBLIC_URL}."
93+
)
94+
else:
95+
if "PUBLIC_BACKEND_URL" not in os.environ:
96+
logger.warning(
97+
"WARNING: Baserow is configured to use a PUBLIC_BACKEND_URL of "
98+
f"{settings.PUBLIC_BACKEND_URL}. If you attempt to access Baserow on any other "
99+
"hostname requests to the backend will fail as they will be from an "
100+
"unknown host."
101+
"Please ensure you set PUBLIC_BACKEND_URL if you will be accessing "
102+
f"Baserow from any other URL then {settings.PUBLIC_BACKEND_URL}."
103+
)
104+
if "PUBLIC_WEB_FRONTEND_URL" not in os.environ:
105+
logger.warning(
106+
"WARNING: Baserow is configured to use a default PUBLIC_WEB_FRONTEND_URL "
107+
f"of {settings.PUBLIC_WEB_FRONTEND_URL}. Emails sent by Baserow will use links "
108+
f"pointing to {settings.PUBLIC_WEB_FRONTEND_URL} when telling users how to "
109+
"access your server. "
110+
"If this is incorrect please ensure you have set PUBLIC_WEB_FRONTEND_URL to "
111+
"the URL where users can access your Baserow server."
112+
)

backend/src/baserow/config/settings/base.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -723,40 +723,15 @@ def __setitem__(self, key, value):
723723
},
724724
}
725725

726-
BASEROW_PUBLIC_URL = os.getenv("BASEROW_PUBLIC_URL")
726+
BASEROW_PUBLIC_URL = os.getenv("BASEROW_PUBLIC_URL", "")
727727
if BASEROW_PUBLIC_URL:
728728
PUBLIC_BACKEND_URL = BASEROW_PUBLIC_URL
729729
PUBLIC_WEB_FRONTEND_URL = BASEROW_PUBLIC_URL
730-
if BASEROW_PUBLIC_URL == "http://localhost":
731-
print(
732-
"WARNING: Baserow is configured to use a BASEROW_PUBLIC_URL of "
733-
"http://localhost. If you attempt to access Baserow on any other hostname "
734-
"requests to the backend will fail as they will be from an unknown host. "
735-
"Please set BASEROW_PUBLIC_URL if you will be accessing Baserow "
736-
"from any other URL then http://localhost."
737-
)
738730
else:
739731
PUBLIC_BACKEND_URL = os.getenv("PUBLIC_BACKEND_URL", "http://localhost:8000")
740732
PUBLIC_WEB_FRONTEND_URL = os.getenv(
741733
"PUBLIC_WEB_FRONTEND_URL", "http://localhost:3000"
742734
)
743-
if "PUBLIC_BACKEND_URL" not in os.environ:
744-
print(
745-
"WARNING: Baserow is configured to use a PUBLIC_BACKEND_URL of "
746-
"http://localhost:8000. If you attempt to access Baserow on any other "
747-
"hostname requests to the backend will fail as they will be from an "
748-
"unknown host."
749-
"Please ensure you set PUBLIC_BACKEND_URL if you will be accessing "
750-
"Baserow from any other URL then http://localhost."
751-
)
752-
if "PUBLIC_WEB_FRONTEND_URL" not in os.environ:
753-
print(
754-
"WARNING: Baserow is configured to use a default PUBLIC_WEB_FRONTEND_URL "
755-
"of http://localhost:3000. Emails sent by Baserow will use links pointing "
756-
"to http://localhost:3000 when telling users how to access your server. If "
757-
"this is incorrect please ensure you have set PUBLIC_WEB_FRONTEND_URL to "
758-
"the URL where users can access your Baserow server."
759-
)
760735

761736
BASEROW_EMBEDDED_SHARE_URL = os.getenv("BASEROW_EMBEDDED_SHARE_URL")
762737
if not BASEROW_EMBEDDED_SHARE_URL:

backend/src/baserow/config/wsgi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.conf import settings
1111
from django.core.wsgi import get_wsgi_application
1212

13-
from baserow.config.helpers import check_lazy_loaded_libraries
13+
from baserow.config.helpers import check_lazy_loaded_libraries, log_env_warnings
1414
from baserow.core.telemetry.telemetry import setup_logging, setup_telemetry
1515

1616
# The telemetry instrumentation library setup needs to run prior to django's setup.
@@ -28,3 +28,6 @@
2828
# Check that libraries meant to be lazy-loaded haven't been imported at startup.
2929
# This runs after Django is fully loaded, so it catches imports from all apps.
3030
check_lazy_loaded_libraries()
31+
32+
# Finally log any warnings about the environment variables that can help debug issues.
33+
log_env_warnings()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import django.db.models.deletion
2+
from django.conf import settings
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("core", "0110_totpusedcode"),
9+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
10+
]
11+
12+
operations = [
13+
migrations.SeparateDatabaseAndState(
14+
state_operations=[
15+
migrations.AlterField(
16+
model_name="twofactorauthprovidermodel",
17+
name="user",
18+
field=models.OneToOneField(
19+
help_text="User that setup 2fa with this provider",
20+
on_delete=django.db.models.deletion.CASCADE,
21+
related_name="two_factor_auth_provider",
22+
to=settings.AUTH_USER_MODEL,
23+
),
24+
),
25+
],
26+
database_operations=[],
27+
),
28+
]

backend/src/baserow/core/two_factor_auth/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ class TwoFactorAuthProviderModel(
2121
related_name="two_factor_auth_providers",
2222
on_delete=models.CASCADE,
2323
)
24-
user = models.ForeignKey(
24+
user = models.OneToOneField(
2525
"auth.User",
26-
unique=True,
2726
on_delete=models.CASCADE,
28-
related_name="two_factor_auth_providers",
27+
related_name="two_factor_auth_provider",
2928
help_text="User that setup 2fa with this provider",
3029
)
3130

backend/src/baserow/manage.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ def enable_debugger():
1313
debugger_port = int(os.environ.get("BASEROW_BACKEND_DEBUGGER_PORT", 5678))
1414
debugpy.listen(("0.0.0.0", debugger_port)) # nosec
1515
print(f"Debugger attached! Listening on 0.0.0.0:{debugger_port}")
16-
else:
17-
print(
18-
"Debugger disabled. Set the env variable "
19-
"BASEROW_BACKEND_DEBUGGER_ENABLED=True to enable it."
20-
)
2116

2217

2318
def main():

0 commit comments

Comments
 (0)