-
Notifications
You must be signed in to change notification settings - Fork 43
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
'Repo.insert' throw 'IndexError' sometimes #95
Comments
#95 use 'first?' to prevent 'IndexError' when insert/update
fixed by #96 |
@fridgerator I'm still experience IndexError on master. And "Unexpected byte 0xff in UTF-8 byte sequence" as well. I don't know how to debug this, I'm new in Crystal. |
You get the unexpected byte sequence only on insert statements with mysql? |
@fridgerator I'm experience this with postgresql. I'm parsing json and then insert changeset.
Very confusing. I'm already successfully record other records. With insert
Without insert
I found that if I replace nil values with values then all 6 will be recorded. But rescue will print out
|
@onemanstartup are you able to share your schema and json that you are parsing? I tried replicating locally and couldn't |
@fridgerator This is the code. I don't understand why records persists but throw errors.. strange.. class Ticker < Crecto::Model
schema "tickers", primary_key: false do
field :market, String
field :currency, String
field :ticker, String
field :price, Float64
field :bid, Float64
field :ask, Float64
field :low_24h, Float64
field :high_24h, Float64
field :avg_24h, Float64
field :volume_24h, Float64
field :volume_30d, Float64
set_created_at_field nil
set_updated_at_field nil
end
validate_required [:market]
validate_format :market, /^[a-zA-Z]*$/
end CREATE TABLE tickers (
time TIMESTAMPTZ NOT NULL DEFAULT now(),
market TEXT NOT NULL,
currency TEXT NOT NULL,
ticker TEXT NOT NULL,
price numeric NOT NULL,
bid numeric NULL,
ask numeric NULL,
low_24h numeric NULL,
high_24h numeric NULL,
avg_24h numeric NULL,
volume_24h numeric NULL,
volume_30d numeric NULL
); {"bch":{"volume":"214659.4839","last":"418000","yesterday_last":"352400","yesterday_low":"348000","high":"451500","currency":"bch","low":"349700","yesterday_first":"353500","yesterday_volume":"12689.9568","yesterday_high":"360300","first":"351400"},"qtum":{"volume":"2417040.9742","last":"12830","yesterday_last":"11960","yesterday_low":"11790","high":"13200","currency":"qtum","low":"11950","yesterday_first":"12060","yesterday_volume":"657970.4149","yesterday_high":"12360","first":"11980"},"errorCode":"0","etc":{"volume":"983336.4399","last":"13700","yesterday_last":"13430","yesterday_low":"13230","high":"14050","currency":"etc","low":"13260","yesterday_first":"13470","yesterday_volume":"477616.7548","yesterday_high":"13690","first":"13440"},"result":"success","btc":{"volume":"4240.6907","last":"6372000","yesterday_last":"6347000","yesterday_low":"6200000","high":"6486500","currency":"btc","low":"6300000","yesterday_first":"6332500","yesterday_volume":"5541.9419","yesterday_high":"6499500","first":"6375000"},"timestamp":"1508249874","eth":{"volume":"83368.7347","last":"367100","yesterday_last":"380400","yesterday_low":"368500","high":"383000","currency":"eth","low":"365000","yesterday_first":"375000","yesterday_volume":"165312.9340","yesterday_high":"394900","first":"381400"},"xrp":{"volume":"306820375.5870","last":"288","yesterday_last":"319","yesterday_low":"293","high":"323","currency":"xrp","low":"278","yesterday_first":"296","yesterday_volume":"334760612.5759","yesterday_high":"327","first":"323"}} JSON.parse(response.body).each do |k, v|
next if k == "errorCode" || k == "result" || k == "timestamp"
ticker = Mapping::Ticker.from_json(v.to_json)
new_ticker = Ticker.new
new_ticker.market = @market
new_ticker.currency = k.to_s
new_ticker.ticker = "KRW"
new_ticker.price = ticker.last.to_f
new_ticker.low_24h = ticker.low.to_f
new_ticker.high_24h = ticker.high.to_f
new_ticker.volume_24h = ticker.volume.to_f
new_ticker.avg_24h = 0.to_f
new_ticker.volume_30d = 0.to_f
new_ticker.bid = 0.to_f
new_ticker.ask = 0.to_f
changeset = Ticker.changeset(new_ticker)
if changeset.valid?
begin
Repo.insert(changeset)
rescue ex
puts "insert error - #{ex}"
end
else
puts changeset.errors
end
end |
If you change the |
@fridgerator I tried set types to PG::Numeric in Crecto::Model, but it's doesn't work. It seems either I don't understand how casting works in pg shard or crystal lacks decimal field leads to this. Anyway thanks for helping out, will save in floats for now, until figure out how this works. |
yeah you'll have to use float right now, |
I'm still getting this error with Crecto
|
Looks like it was bad permissions settings on my part. Solved by making my dev
|
Nevermind, still get the |
@timkendall Does this happen all the time or randomly? It would be great to get a log of the sql generated |
All of the time - I'll add that when I get back to my personal computer. |
@timkendall Creating a table with withe sql you posted, the following is working for me (crystal 0.24.2, crecto master branch)
|
@timkendall did that fix end up working for you? Or can you let me know if you're still getting this error? I know this is an old issue. |
Sometimes simple insert query result is empty array
[]
,though all data were inserted to table correctly.
https://github.com/Crecto/crecto/blob/master/src/crecto/repo.cr#L184
The error is coming from
first
.I couldn't find any pattern, it looks like randomly occur.
mysql-5.6
The text was updated successfully, but these errors were encountered: