Bug Report: Daily Reports & Squad Edit Issues

by SLV Team 46 views
Bug Report: Daily Reports & Squad Edit Issues

Hey guys! Today, we're diving deep into a couple of nasty bugs that have been plaguing the daily reports and squad editing features. Let's break it down in a way that's easy to understand, even if you're not a tech whiz. We'll go through the issues, explain what's causing them, and hopefully point you in the right direction to get things fixed.

PROBLEM #1: Rot in Your Database

So, the first major headache is with the daily reports. It turns out there's some serious data corruption going on in your database. This is causing the reports to fail, and it's all stemming from how the connected_squads field is being handled. Let's get into the details, and how you can work on solving this critical issue.

The Evidence

Here’s the raw error message:

remnawave_bot_db     | 2025-11-01T11:11:40.192887635Z 2025-11-01 11:11:40.192 UTC [650] ERROR:  cannot get array length of a scalar
remnawave_bot_db     | 2025-11-01T11:11:40.192920627Z 2025-11-01 11:11:40.192 UTC [650] STATEMENT:  SELECT count(distinct(subscriptions.user_id)) AS count_1 
remnawave_bot_db     | 2025-11-01T11:11:40.192923072Z   FROM subscriptions 
remnawave_bot_db     | 2025-11-01T11:11:40.192925917Z   WHERE subscriptions.connected_squads IS NULL OR jsonb_array_length(CAST(subscriptions.connected_squads AS JSONB)) = $1::INTEGER

Translation: From Bot-Speak to Human

Okay, so what does all that gibberish actually mean? When you ask the bot for a report, it queries the database. Specifically, it's trying to count all the users who have an empty list in the connected_squads field. Makes sense, right? It wants to know who's not currently connected to any squads. However, the database is throwing a fit because some of the entries in that connected_squads field aren't empty lists ([]) at all. Instead, they're plain old numbers or strings (scalars). The database is essentially saying, "Hey, I can't calculate the length of a brick!" It's expecting a list, but it's getting something else entirely. This is usually caused by issues with the types stored in the connected_squads field. If you are expecting the field to store arrays then you must ensure that other types are not permitted to be stored in it. This can be achieved using constraints on the database column.

The Bottom Line

Your reports are broken because your database is full of garbage! The connected_squads field should only contain lists (arrays), but it's got other types of data mixed in, causing the query to fail. You'll need to clean up your database and ensure that the data types are consistent. A common cause of this can be that the input is not validated when creating the value and inserting into the database, and you may wish to perform validation prior to the insertion. You should check all the code that reads and writes the connected_squads field and ensure it is converting to the correct type.

PROBLEM #2: Wonky Code in the Admin Panel

Alright, let's move on to the second issue: problems with the admin panel, specifically when editing squads. This one's a bit different, but just as annoying. When attempting to edit squad information in the backend system, things can go sideways quickly due to a critical code execution error. Let's get right to the issue!

The Evidence

Here's the error message we're dealing with:

remnawave_bot        | 2025-11-01T11:14:51.184856774Z or mount method to a bot instance `method.as_(bot)` and then call it `await method`
remnawave_bot        | 2025-11-01T11:14:51.184882871Z Traceback (most recent call last):
remnawave_bot        |   File "/app/app/utils/decorators.py", line 53, in wrapper
remnawave_bot        |     return await func(*args, **kwargs)
remnawave_bot        |   File "/app/app/handlers/admin/remnawave.py", line 1615, in show_squad_edit_menu
remnawave_bot        |     await callback.answer()
remnawave_bot        | RuntimeError: This method is not mounted to a any bot instance, please call it explicilty with bot instance `await bot(method)`

Translation: From Bot-Speak to Human

Okay, so what's happening here? When you click buttons in the admin panel to edit a squad, the code tries to execute a command called callback.answer(). This command is responsible for stopping the little loading spinner on the button, letting you know that the action has been processed. However, the code doesn't know which bot instance should execute this command. The bot object, which should be available in that context, is missing or undefined. It's like shouting "Go!" in an empty room. There's no one there to respond. This points to a bug in the bot's code where it's not properly passing the bot instance to the function that handles the button click.

The Bottom Line

This is a straight-up code bug. The bot object is not being correctly passed to the callback.answer() function. You need to trace the execution flow of the code and figure out why the bot instance is not available in that context. This could be due to a scope issue, an incorrect import, or a problem with how the function is being called. To resolve this error you will need to ensure that when creating the callback you use method.as_(bot) to attach the current instance of the bot. The bot also has to be called explicitly using await bot(method).

Wrapping Up

So, there you have it. Two distinct bugs causing problems with your daily reports and squad editing features. The first is due to data corruption in your database, while the second is a code bug in your admin panel. Addressing these issues will be important for maintaining the health and functionality of your system. Debugging these problems is going to require some digging into the codebase and potentially updating your database schema. Good luck, and happy debugging!