Skip to content

feat/add-popular-tasks#1708

Open
floscodes wants to merge 21 commits intoloco-rs:feat/add-popular-tasksfrom
floscodes:feat/add-popular-tasks
Open

feat/add-popular-tasks#1708
floscodes wants to merge 21 commits intoloco-rs:feat/add-popular-tasksfrom
floscodes:feat/add-popular-tasks

Conversation

@floscodes
Copy link

This PR adds a user deletion functionality to popular tasks.

@floscodes
Copy link
Author

floscodes commented Dec 22, 2025

Hi @kaplanelad,

I refactored the code and fixed the remaining issues.

@floscodes
Copy link
Author

Hi @kaplanelad,

is it ok like this?

@kaplanelad
Copy link
Contributor

Hi @kaplanelad,

is it ok like this?

looks better. thanks.
can you check the ci?

@floscodes floscodes requested a review from kaplanelad January 2, 2026 09:33
@floscodes
Copy link
Author

Hi @kaplanelad,

just a quick heads-up: the CI is now passing and all tests are running successfully.

Thank you!

@kaplanelad
Copy link
Contributor

How group related to delete user task?

@floscodes
Copy link
Author

floscodes commented Jan 8, 2026

The delete-method from the ActiveModelTrait requires the groups table to exist:

let _deleted_user = user_to_delete
            .into_active_model()
            .delete(&app_context.db)
            .await
            .map_err(|err| {
                tracing::error!(message = err.to_string(), "could not delete user");
                Error::string(&format!("Failed to delete user. err: {err}",))
            })?;

otherwise the test fails with the following error:

Execution Error: error returned from database:
(code: 1) no such table: main.groups

That's why I had to add the groups migration file.

this seems to be caused by the following test:

tester.run_generate_migration(&vec![
    "CreateJoinTableUsersAndGroups",
    "count:int",
]);

@kaplanelad
Copy link
Contributor

From where the group came from?

@floscodes
Copy link
Author

From where the group came from?

That also caught my attention 🙂

I didn’t intentionally introduce groups on my side.

From what I could tell, the groups table is implicitly required by the ActiveModel::delete implementation. When the table is missing, the delete call fails at runtime, which is what caused the test to break.

I traced this back to the CreateJoinTableUsersAndGroups migration generated in the test. That seems to be where the dependency comes from, even though groups itself isn’t created explicitly beforehand.

The migration was added purely to make the test pass and avoid the runtime error — happy to change this if there’s a more intended approach 👍

@kaplanelad
Copy link
Contributor

Please clarify where the groups migration comes from specifically, explain that ActiveModelTrait::delete requires all related tables to exist. this is not clear to me

Also, please remove the commented-out test code in new.rs not sure if why it commended

@floscodes
Copy link
Author

Hi @kaplanelad,

sorry for the delay.

It looks like the groups table may originate from one of the wizard tests. In loco/loco-new/tests/wizard/new.rs, the function test_combination calls:

tester.run_generate_migration(&vec!["CreateJoinTableUsersAndGroups", "count:int"]);

Inside run_generate_migration, the base command is constructed with:

let base_command = vec!["loco", "generate", "migration"];

and then extended with CreateJoinTableUsersAndGroups. The migration is executed via self.run_migrate, which during the test run creates a join table between users and groups.

From what I can see, creating a user in the wizard task works without issues. However, when the user is deleted, the presence of the groups table seems to become relevant. My assumption is that the wizard cannot find the corresponding migration in the base template, which may be why the deletion step fails. As a result, the wizard test appears to implicitly require the groups table to exist when deleting a user.

One possible explanation could also be related to how the ORM handles relations. Creating a user only inserts into the users table, so the join table might be not required at that stage. However, when deleting a user, the ORM may attempt to handle related records (for example in a users_groups join table). If those related tables do not exist, the deletion step could fail even though the insert worked correctly.

Please let me know if I might be misunderstanding something here.

Best regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants