Project

General

Profile

Actions

Improvement #2002

closed

xmera Omnia - Improvement #1837: Improvements of diverse modules

Via API: A RuntimeError occurred in projects#create

Added by liaham about 1 year ago. Updated 8 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Compatible Redmine Version:

Description

A RuntimeError occurred in projects#create:

  Project id= with parent_id=0: parent missing or without 'lft' value
  lib/redmine/nested_set/project_nested_set.rb:49:in `target_lft'
  lib/redmine/nested_set/project_nested_set.rb:60:in `add_to_nested_set'
  app/controllers/projects_controller.rb:111:in `create'
  plugins/redmine_project_types/lib/project_types/overrides/projects_controller_patch.rb:49:in `create'
  lib/redmine/sudo_mode.rb:61:in `sudo_mode'

Relative URL:

/projects.json?key=<key>

Parameters:

{"project"=>{"name"=>"1111", "identifier"=>"zdv_1111", "description"=>"Firma 1111", "parent_id"=>0}, "key"=>"[FILTERED]", "controller"=>"projects", "action"=>"create", "format"=>"json"}
Actions #1

Updated by liaham about 1 year ago

  • Status changed from New to In Progress
  • Assignee set to liaham

This error message: Project id= with parent_id=0: parent missing or without 'lft' value is raised when a user provides a parent_id for a project which does not exist.

Actions #2

Updated by liaham about 1 year ago

In Redmine::NestedSet::ProjectNestedSet#target_lft the code could be improved like this:

      def target_lft
        return 1 unless parent_id.to_i.positive? # <-- Using guard clause

        siblings_rgt =
          self.class.where(:parent_id => parent_id).where("name < ?", name).maximum(:rgt)
        if siblings_rgt
          siblings_rgt + 1
        elsif parent_id
          parent_lft = self.class.where(:id => parent_id).pick(:lft)
          unless parent_lft
            raise "Project id=#{id} with parent_id=#{parent_id}: parent missing or without 'lft' value"
          end

          parent_lft + 1
        else
          1
        end
      end

Using parent_id.to_i transforms like this:

  • nil -> 0
  • 0 -> 0
  • an integer value greater zero -> an integer value greater zero
  • any String value -> to any integer value greater zero or zero for anything else
Actions #3

Updated by liaham about 1 year ago

  • Tracker changed from Bug to Improvement
  • Target version changed from unplanned to 4.3.0
  • Parent task deleted (#1934)
  • Affected Version deleted (4.2.1)
Actions #4

Updated by liaham about 1 year ago

  • Project changed from xmera Omnia to Redmine
  • Category deleted (30)
  • Target version deleted (4.3.0)
  • Parent task set to #1837
Actions #5

Updated by liaham 8 months ago

  • Status changed from In Progress to Rejected

Rejected since project_id=0 is managed what should be sufficient.

Actions

Also available in: Atom PDF