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

Error creating record. #504

Open
antarr opened this issue Feb 4, 2024 · 1 comment
Open

Error creating record. #504

antarr opened this issue Feb 4, 2024 · 1 comment

Comments

@antarr
Copy link

antarr commented Feb 4, 2024

I'm trying to use granite in a serverless function. I'm getting an error when attempting to create record.

Error Message

Expected String but was Int at line 1, column 16

Error Backtrace

/usr/local/Cellar/crystal/1.9.2/share/crystal/src/json/pull_parser.cr:705:5 in 'raise'
lib/sidekiq/src/sidekiq/job.cr:81:13 in '->'
lib/sidekiq/src/sidekiq/middleware.cr:81:13 in 'next_link'
/usr/local/Cellar/crystal/1.9.2/share/crystal/src/crystal/system/unix/time.cr:84:3 in 'next_link'
lib/sidekiq/src/sidekiq/server/processor.cr:149:7 in 'process_one'
lib/sidekiq/src/sidekiq/server/processor.cr:46:9 in '->'
lib/sidekiq/src/sidekiq/server/util.cr:21:9 in '->'
/usr/local/Cellar/crystal/1.9.2/share/crystal/src/fiber.cr:146:11 in 'run'

src/models.cr

require "pg"
require "granite/adapter/pg"

max_pool_size  = ENV.fetch("WORKER_CR_CONCURRENCY") { "5" }.to_i
initial_pool_size = [max_pool_size * 0.3, 1].max.to_i
Granite::Connections << Granite::Adapter::Pg.new(
  name: "pg",
  url: ENV.fetch("DATABASE_URL"),
)

module Models
  class Text < Granite::Base
    connection pg

    table legiscan_model_texts

    column doc_id : Int64, primary:  true
    column bill_id : Int32?
    column type_id : Int32?
    column mime_id : Int32?
    column alt_mime_id : Int32?
    column date : Time?
    column doc : String?
    column mime : String?
    column size : Int32?
    column state_link : String?
    column url : String?
    column text_hash : String?
    column text_size : Int32?
    column alt_doc : String?
    column alt_mime : String?
    column alt_text_size : Int32?
    column alt_state_link : String?
    column alt_text_hash : String?
    column summary : String?
    column text_type : String?
    column created_at : Time?
    column updated_at : Time?

    timestamps
  end
end

src/legiscan.cr

require "dotenv"
require "pg"
require "sidekiq"
require "./models"

Dotenv.load

module Legiscan
  VERSION = "0.0.1"
  DATABASE_URL = ENV["DATABASE_URL"]

  class TextJob
    include Sidekiq::Worker
    # include Models

    sidekiq_options do |opts|
      opts.queue = "legiscan_texts"
    end

    def perform(args : Hash(String, String))
      Models::Text.create(args)
    end
  end
end

schema

# == Schema Information
#
# Table name: legiscan_model_texts
#
#  alt_bill_text  :integer
#  alt_doc        :string
#  alt_mime       :string
#  alt_state_link :string
#  alt_text_hash  :string
#  alt_text_size  :integer
#  date           :date
#  doc            :text
#  mime           :string
#  size           :integer
#  state_link     :string
#  summary        :text
#  text_hash      :string
#  text_size      :integer
#  text_type      :string
#  url            :string
#  created_at     :datetime         not null
#  updated_at     :datetime         not null
#  alt_mime_id    :integer
#  bill_id        :integer          not null, indexed
#  doc_id         :integer          not null, primary key, indexed
#  mime_id        :integer          indexed
#  type_id        :integer          indexed
#

Arguments

 {
    "doc_id": 2133,
    "bill_id": 70264,
    "date": "2010-04-12",
    "type": "Amended",
    "type_id": 3,
    "mime": "text\/html",
    "mime_id": 1,
    "url": "https:\/\/legiscan.com\/CA\/text\/AB1981\/id\/2133",
    "state_link": "http:\/\/www.leginfo.ca.gov\/pub\/09-10\/bill\/asm\/ab_1951-2000\/ab_1981_bill_20100412_amended_asm_v98.html",
    "text_size": 48576,
    "text_hash": "83d2cf3a6e44ea71509c0379c12f8e02",
    "doc": "[FILTERED]",
    "alt_bill_text": 0,
    "alt_mime": "",
    "alt_mime_id": 0,
    "alt_state_link": "",
    "alt_text_size": 0,
    "alt_text_hash": "",
    "alt_doc": ""
}
@mloughran
Copy link

@antarr I doubt this is an issue in Granite – in the stacktrace you posted the error is in lib/sidekiq/src/sidekiq/job.cr. I'm not the maintainer, but regardless I'd suggest closing this issue and opening a more minimal issue if you're still facing difficulties.

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