dosaki / gorm-revel-issue

This project is just to exemplify an issue with Gorm and Revel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with Revel and Gorm

Not sure if this is an actual problem or me doing something stupid.

Problem

gorm throws an error when trying to call db.Create() from within a controller (see app/controllers/app.go).

The database initializing function is inside app/datasource/datasource.go and gets called in app/init.go with

revel.OnAppStart(datasource.AutoInitDB)

How to reproduce:

Requirements

Steps

  1. Start the app with revel run gorm_issue
  2. Go to http://localhost:9000/
  3. See error :(
Runtime Panic
runtime error: invalid memory address or nil pointer dereference

In /github.com/jinzhu/gorm/main.go (around line 407)

402: }
403:
404: // Create insert the value into database
405: func (s *DB) Create(value interface{}) *DB {
406:   scope := s.clone().NewScope(value)
407:   return scope.callCallbacks(s.parent.callbacks.creates).db
408: }
409:
410: // Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition
411: func (s *DB) Delete(value interface{}, where ...interface{}) *DB {

About

This project is just to exemplify an issue with Gorm and Revel

License:GNU General Public License v3.0


Languages

Language:Go 71.0%Language:HTML 29.0%