我不知道这是否是我的代码中的一些交互,或者可能是我正在使用的 shapefile 中的命名约定,但以下代码会产生一条Stack level too deep
消息
def read_shapefile
@shp_path = Dir[File.join( @tmp_path, '*.shp') ].first
srs_database = RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new
factory = RGeo::Geos.factory(:srs_database => srs_database, :srid => 96805)
#factory = RGeo::Geos::CAPIFactory.new
cartesian_preferred_factory = LandUnit.rgeo_factory_for_column(:location)
RGeo::Shapefile::Reader.open(@shp_path, factory: factory) do |file|
file.each do |record|
cartesian_cast = RGeo::Feature.cast(
record.geometry, factory: cartesian_preferred_factory, project: true)
cartesian_cast.each do |poly|
lu = LandUnit.new
lu.guid = record.attributes[@params['guid']].to_s
lu.country_code = @params['country_code']
lu.location = poly
# error happens here!
lu.save
end
end
end
end
模型迁移:
class CreateLandUnits < ActiveRecord::Migration
def change
create_table :land_units do |t|
t.string :country_code, null: false, index: true
t.string :guid, index: true
t.geometry :location, srid: 3785
t.timestamps
end
end
end
schema.rb 的相关部分:
create_table "land_units", force: true do |t|
t.string "country_code", null: false
t.string "guid"
t.datetime "created_at"
t.datetime "updated_at"
t.spatial "location", limit: {:srid=>3785, :type=>"geometry"}
end
add_index "land_units", ["location"], :name => "index_land_units_on_location", :spatial => true
回溯指向active_record/transactions.rb
第 286 行:
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
restore_transaction_record_state
raise # HERE<<<
ensure
clear_transaction_record_state
end
什么都试过了。任何帮助,将不胜感激。
编辑:如果有人想知道这些参数,在失败的调用中他们解析为 guid:'6020048.00',和 country_code:'ca'。
我还应该补充一点,日志显示了这一点:
(0.1ms) BEGIN
SQL (0.6ms) INSERT INTO "land_units" ("country_code", "created_at", "guid", "location", "updated_at")
VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["country_code", "ca"], ["created_at", "2015-03-23 20:59:38.771649"], ["guid", "6020048.00"],
["location", "002000000300000ec90000000100000028c164b311c749d0be4049101977159301c164b311c7508b1140491022249508cfc164b311c7671af24049103f70c23377c164b311c785400940491065d156a4f5c164b311c78493be40491082fd398873c164b311c783e2024049109c841e4650c164b311c78327ba404910ae43343896c164b311c7810e65404910b976a8c3dfc164b311c77c6113404910cf2943e8c7c164b311c777d3ba404910e3e11b1b56c164b311c771ff68404910fdcea7cc13c164b311c7716ef74049110061ae5237c164b311c76d520940491113afcec9eec164b311c7631bad4049114313691234c164b311c75f336f40491154764b6b38c164b311c75249bb40491140bebb55fac164b311c749492e40491135844d8b3fc164b311c740bbbb4049112ae8b30272c164b311c737d9274049111f6444e7acc164b311c72f4d334049111430f7e5f3c164b311c726871640491108fa115ffac164b311c71e34d2404910fe160b0597c164b311c7151806404910f28d86b4f4c164b311c70ca8b0404910e7a793a963c164b311c705b232404910deb9fc574ac164b311c703a91d404910dc20d4806ac164b311c6fb1d64404910d0ed325688c164b311c6f290ef404910c605069167c164b311c6e9e83a404910bacf71a130c164b311c6e0cba9404910af46584a4fc164b311c6f115694049105a80074a79c164b311c6f69ca64049103bc8277f0fc164b311c6facd224049102626e4a97cc164b311c6fec1f340491011192ee217c164b311c703ca8a40490ff67dac4e4ac164b311c707dc6d40490fe171e94d20c164b311c70c6bce40490fc98cc82ecdc164b311c720cc5340490fe45c78305ac164b311c73527f340490ffe8cde5378c164b311c749d0be4049101977159301"], ["updated_at", "2015-03-23 20:59:38.771649"
]]
(0.2ms) ROLLBACK
它显示的 SQL 在控制台中执行得很好!这就是疯狂的一点。这向我表明问题出在一些 before_save 方法上,但我没有定义任何方法。