You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deleting a contact it results in a server 5xx error
Steps to reproduce
Create a contact
Create a reminder attached to the contact
Delete the contact
???
Error
Expected behavior
No Error.
Here is the suggested fix from my LLM:
It looks like the issue is arising because the contact associated with a reminder no longer exists in the database after you deleted it. This causes the $contact object to be null, leading to the error when trying to access its properties.
To handle this gracefully, you can add a null check for the $contact object in your upcomingReminders method. Here’s the updated code with the null check:
publicstaticfunctionupcomingReminders(Vault$vault, User$user): array
{
$currentDate = Carbon::now()->copy();
$currentDate->second = 0;
// first we get all the user notification channels for the users in the vault$userNotificationChannels = $vault->users->flatMap(fn ($u) => $u->notificationChannels);
// then we get all the contact reminders scheduled for those channels$contactRemindersScheduled = $userNotificationChannels->flatMap(
fn ($channel) => $channel->contactReminders()
->wherePivot('scheduled_at', '<=', $currentDate->addDays(30))
->wherePivot('triggered_at', null)
->orderByPivot('scheduled_at', 'asc')
->get()
);
// finally, we get all the details about those reminders$remindersCollection = $contactRemindersScheduled->map(function ($reminder) use ($vault, $user) {
$contact = $reminder->contact;
if (!$contact || $contact->vault_id !== $vault->id) {
returnnull;
}
$scheduledAtDate = Carbon::createFromFormat('Y-m-d H:i:s', $reminder->pivot->scheduled_at);
return [
'id' => $reminder->id,
'label' => $reminder->label,
'scheduled_at' => DateHelper::format($scheduledAtDate, $user),
'contact' => [
'id' => $contact->id,
'name' => $contact->name,
'avatar' => $contact->avatar,
'url' => [
'show' => route('contact.show', [
'vault' => $contact->vault_id,
'contact' => $contact->id,
]),
],
],
];
});
// this line removes the null values that are added when the contact// is not in the vault (or doesn't exist)$remindersCollection = $remindersCollection->filter(fn ($value) => $value != null);
return [
'reminders' => $remindersCollection,
'url' => [
'index' => route('vault.reminder.index', [
'vault' => $vault->id,
]),
],
];
}
Explanation:
Null Check: Added a check if (!$contact || $contact->vault_id !== $vault->id) to ensure that the contact exists and belongs to the correct vault before accessing its properties.
Filtering: The existing filter at the end will remove any null entries, ensuring that only valid reminders are returned.
This should prevent the error from occurring when a contact is deleted. If you still encounter issues, make sure to clear the cache and config:
php artisan cache:clear
php artisan config:clear
Let me know if this resolves the issue! 🐬
Environment
Your own self-hosted instance (v5 a.k.a chandler version or main branch)
Bug description
When deleting a contact it results in a server 5xx error
Steps to reproduce
Expected behavior
No Error.
Here is the suggested fix from my LLM:
It looks like the issue is arising because the contact associated with a reminder no longer exists in the database after you deleted it. This causes the
$contact
object to be null, leading to the error when trying to access its properties.To handle this gracefully, you can add a null check for the
$contact
object in yourupcomingReminders
method. Here’s the updated code with the null check:app/Domains/Vault/ManageVault/Web/ViewHelpers/VaultShowViewHelper.php
Explanation:
if (!$contact || $contact->vault_id !== $vault->id)
to ensure that the contact exists and belongs to the correct vault before accessing its properties.This should prevent the error from occurring when a contact is deleted. If you still encounter issues, make sure to clear the cache and config:
Let me know if this resolves the issue! 🐬
Environment
Your own self-hosted instance (v5 a.k.a chandler version or main branch)
Version of Monica
Version 5.0.0-beta.4 — commit 0400350.
Installation method
Docker image
Web server
Other
Database engine version
PostgreSQL
Additional info
Running this in Kubernetes with the monica-next:main image.
Logs:
The text was updated successfully, but these errors were encountered: