Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

really_destroy! updates column with datetime even when using sentinel_value #326

Closed
mhaylock opened this issue May 17, 2016 · 1 comment
Closed

Comments

@mhaylock
Copy link

Using paranoia 2.1.5, I have a model setup using the sentinel_value option, as documented in the README under "Indexes", e.g:

add_column :clients, :active, :boolean
add_index :clients, [:group_id, :active], unique: true

class Client < ActiveRecord::Base
  # optionally have paranoia make use of your unique column, so that
  # your lookups will benefit from the unique index
  acts_as_paranoid column: :active, sentinel_value: true

  def paranoia_restore_attributes
    {
      deleted_at: nil,
      active: true
    }
  end

  def paranoia_destroy_attributes
    {
      deleted_at: current_time_from_proper_timezone,
      active: nil
    }
  end
end

When calling really_destroy! on this model the following warning is generated by Rails (4.2.6):

DEPRECATION WARNING: You attempted to assign a value which is not explicitly `true` or `false` (2016-05-17 02:02:23 UTC) to a boolean column. Currently this value casts to `false`. This will change to match Ruby's semantics, and will cast to `true` in Rails 5. If you would like to maintain the current behavior, you should explicitly handle the values you would like cast to `false`.

This is because paranoia is writing the current datetime into the paranoia column (active in this example), at this line: https://github.com/rubysherpas/paranoia/blob/core/lib/paranoia.rb#L146. I think this should probably use paranoia_destroy_attributes instead?

However it's not clear to me why it is even updating the column if it then goes and deletes the row from the database? Why update the column at all?

@jigneshkhokhani
Copy link

jigneshkhokhani commented Sep 8, 2016

I have same issue with rails 5.0.0.1 and ruby 2.3.1.
Run @user.really_destroy! and @user.destroy both update deleted_at column.

class User
  acts_as_paranoid
end

Because of i write acts_as_paranoid two time in model and removing one of them solved my problem.

steverice added a commit to steverice/paranoia that referenced this issue Jul 13, 2017
This removes the assumption from `really_destroy!` that there is
only one column value, the deletion date, that needs to be updated
on a model that is being `really_destroy!`ed. Instead, use the
defined `paranoia_destroy_attributes` as they are used in `destroy`
and other calls.

This prevents an issue where the DBMS will complain when trying to
`really_destroy!` one of these models, given that paranoia is
attempting to insert a DateTime value into a boolean (or otherly-
typed) column.

Fixes rubysherpas#326
karunkumar1ly pushed a commit to edcast/paranoia that referenced this issue Feb 6, 2024
This removes the assumption from `really_destroy!` that there is
only one column value, the deletion date, that needs to be updated
on a model that is being `really_destroy!`ed. Instead, use the
defined `paranoia_destroy_attributes` as they are used in `destroy`
and other calls.

This prevents an issue where the DBMS will complain when trying to
`really_destroy!` one of these models, given that paranoia is
attempting to insert a DateTime value into a boolean (or otherly-
typed) column.

Fixes rubysherpas#326
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

No branches or pull requests

2 participants