Teslamate: Postgres issue starting up / vid "has already been taken"

Created on 13 Aug 2019  路  6Comments  路  Source: adriankumpf/teslamate

I had teslamate working on my Ubuntu computer, but it's having issues now.

teslamate_1 | 13:41:10.682 [info] Already up
teslamate_1 | 13:41:16.681 [info] Running TeslaMateWeb.Endpoint with cowboy 2.6.3 at :::4000 (http)
teslamate_1 | 13:41:16.681 [info] Access TeslaMateWeb.Endpoint at http://192.168.10.51
teslamate_1 | 13:41:16.760 [info] Found car 'Kevin Model 3'
teslamate_1 | 13:41:16.773 [info] Application teslamate exited: TeslaMate.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeslaMate.Vehicles
teslamate_1 | * (EXIT) an exception was raised:
teslamate_1 | *
(MatchError) no match of right hand side value: {:error, #Ecto.Changeset}
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:70: TeslaMate.Vehicles.create_new!/1
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:25: anonymous fn/2 in TeslaMate.Vehicles.init/1
teslamate_1 | (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
teslamate_1 | (teslamate) lib/teslamate/vehicles.ex:25: TeslaMate.Vehicles.init/1
teslamate_1 | (stdlib) supervisor.erl:295: :supervisor.init/1
teslamate_1 | (stdlib) gen_server.erl:374: :gen_server.init_it/2
teslamate_1 | (stdlib) gen_server.erl:342: :gen_server.init_it/6
teslamate_1 | (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
teslamate_1 | {"Kernel pid terminated",application_controller,"{application_start_failure,teslamate,{{shutdown,{failed_to_start_child,'Elixir.TeslaMate.Vehicles',{{badmatch,{error,#{'__struct__' => 'Elixir.Ecto.Changeset',action => insert,changes => #{efficiency => 0.153,eid => 36230209430047724,model => <<\"M3\">>,vid => 1749778265},constraints => [#{constraint => <<\"cars_vid_index\">>,error_message => <<\"has already been taken\">>,error_type => unique,field => vid,match => exact,type => unique},#{constraint => <<\"cars_eid_index\">>,error_message => <<\"has already been taken\">>,error_type => unique,field => eid,match => exact,type => unique}],data => #{'__meta__' => #{'__struct__' => 'Elixir.Ecto.Schema.Metadata',context => nil,prefix => nil,schema => 'Elixir.TeslaMate.Log.Car',source => <<\"cars\">>,state => built},'__struct__' => 'Elixir.TeslaMate.Log.Car',charging_processes => #{'__cardinality__' => many,'__field__' => charging_processes,'__owner__' => 'Elixir.TeslaMate.Log.Car','__struct__' => 'Elixir.Ecto.Association.NotLoaded'},drives => #{'__cardinality__' => many,'__field__' => drives,'__owner__' => 'Elixir.TeslaMate.Log.Car','__struct__' => 'Elixir.Ecto.Association.NotLoaded'},efficiency => nil,eid => 36230209430047724,id => nil,inserted_at => nil,model => nil,positions => #{'__cardinality__' => many,'__field__' => positions,'__owner__' => 'Elixir.TeslaMate.Log.Car','__struct__' => 'Elixir.Ecto.Association.NotLoaded'},updated_at => nil,vid => 1749778265},empty_values => [<<>>],errors => [{vid,{<<\"has already been taken\">>,[{constraint,unique},{constraint_name,<<\"cars_vid_index\">>}]}}],filters => #{},params => #{<<\"efficiency\">> => 0.153,<<\"eid\">> => 36230209430047724,<<\"model\">> => <<\"M3\">>,<<\"vid\">> => 1749778265},prepare => [],repo => 'Elixir.TeslaMate.Repo',repo_opts => [],required => [eid,vid,model,efficiency],types => #{charging_processes => {assoc,#{'__struct__' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => charging_processes,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.ChargingProcess',related => 'Elixir.TeslaMate.Log.ChargingProcess',related_key => car_id,relationship => child,unique => true,where => []}},drives => {assoc,#{'__struct__' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => drives,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.Drive',related => 'Elixir.TeslaMate.Log.Drive',related_key => car_id,relationship => child,unique => true,where => []}},efficiency => float,eid => integer,id => id,inserted_at => naive_datetime,model => string,positions => {assoc,#{'__struct__' => 'Elixir.Ecto.Association.Has',cardinality => many,defaults => [],field => positions,on_cast => nil,on_delete => nothing,on_replace => raise,owner => 'Elixir.TeslaMate.Log.Car',owner_key => id,queryable => 'Elixir.TeslaMate.Log.Position',related => 'Elixir.TeslaMate.Log.Position',related_key => car_id,relationship => child,unique => true,where => []}},updated_at => naive_datetime,vid => integer},'valid?' => false,validations => []}}},[{'Elixir.TeslaMate.Vehicles','create_new!',1,[{file,\"lib/teslamate/vehicles.ex\"},{line,70}]},{'Elixir.TeslaMate.Vehicles','-init/1-fun-0-',2,[{file,\"lib/teslamate/vehicles.ex\"},{line,25}]},{'Elixir.Enum','-map/2-lists^map/1-0-',2,[{file,\"lib/enum.ex\"},{line,1336}]},{'Elixir.TeslaMate.Vehicles',init,1,[{file,\"lib/teslamate/vehicles.ex\"},{line,25}]},{supervisor,init,1,[{file,\"supervisor.erl\"},{line,295}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}},{'Elixir.TeslaMate.Application',start,[normal,[]]}}}"}
teslamate_1 | Kernel pid terminated (application_controller) ({application_start_failure,teslamate,{{shutdown,{failed_to_start_child,'Elixir.TeslaMate.Vehicles',{{badmatch,{error,#{'__struct__' => 'Elixir.Ecto.Chan
teslamate_1 |
teslamate_1 | Crash dump is being written to: erl_crash.dump...done
db_1 | 2019-08-13 20:41:20.582 UTC [685] LOG: incomplete startup packet
teslamate_1 | 13:41:22.813 [info] Already up

I tried connecting to the docker-compose psql and looking at the database directly, but it seemed to be fine:

sudo docker-compose run --rm db psql -h db -U teslamate

teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------+-------+-----------
public | addresses | table | teslamate
public | cars | table | teslamate
public | charges | table | teslamate
public | charging_processes | table | teslamate
public | drives | table | teslamate
public | geofences | table | teslamate
public | positions | table | teslamate
public | schema_migrations | table | teslamate
public | settings | table | teslamate
public | states | table | teslamate
public | tokens | table | teslamate
public | updates | table | teslamate
(12 rows)

I'm not sure how to get this fixed without wiping my entire docker install. Help?

solved

Most helpful comment

FYI, the user needs to run the docker-compose in one ssh window and let it continue to error itself out, while you connect to that docker install with the command to command line Postgres in another SSH window:

sudo docker-compose run --rm db psql -h db -U teslamate

I didn't know much about how Docker worked until today. Even less about Postgres. Took me forever to figure out how to connect to a Postgres database inside of a Docker container.

All 6 comments

Someone else reported the same issue today. The underlying problem is actually a quirk on Tesla's end.

They recently changed the IDs (!!!) of some cars. See https://github.com/timdorr/tesla-api/issues/139

Unfortunately you have to fix it manually by updating the entry in the database table "cars". Change the eid of entry that has the vid 1749778265 to "36230209430047724" (I got those values from the log output you posted).

__Edit:__ This is how it should be

eid: 36230209430047724
vid: 1749778265

Well that's annoying of Tesla to do that.

kevin@NUC-TV:~/teslamate$ sudo docker-compose run --rm db psql -h db -U teslamate
[sudo] password for kevin:
Password for user teslamate:
psql (11.5 (Debian 11.5-1.pgdg90+1))
Type "help" for help.

teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# UPDATE cars set vid=36230209430047724 ;
UPDATE 1
teslamate=#

That fixed that issue... now it's saying this:

teslamate_1 | Server: 192.168.10.51:4000 (http)
teslamate_1 | Request: GET /
teslamate_1 | * (exit) exited in: :gen_statem.call(:"1", :summary, :infinity)
teslamate_1 | *
(EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

This happens whenever I attempt to view the page at port:4000. Ideas?

You might have changed the wrong id :)

This is how it should be:

eid: 36230209430047724
vid: 1749778265

Yup, I did that wrong, had to delete the new car.

teslamate=# DELETE FROM cars where eid=36230209430047724;
DELETE 1
teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+-------------------+-------+------------+---------------------+---------------------
1 | 19822922099185452 | 36230209430047724 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

teslamate=# update cars set eid=36230209430047724 ;
UPDATE 1
teslamate=# update cars set vid=1749778265 ;
UPDATE 1
teslamate=# SELECT * from cars;
id | eid | vid | model | efficiency | inserted_at | updated_at
----+-------------------+------------+-------+------------+---------------------+---------------------
1 | 36230209430047724 | 1749778265 | M3 | 0.153 | 2019-07-31 17:46:32 | 2019-07-31 17:46:32
(1 row)

Thanks for your quick help. It's working again!

Thanks for your quick help. It's working again!

Awesome!

There may be others affected by this problem as well. I'll pin this issue 馃憤

FYI, the user needs to run the docker-compose in one ssh window and let it continue to error itself out, while you connect to that docker install with the command to command line Postgres in another SSH window:

sudo docker-compose run --rm db psql -h db -U teslamate

I didn't know much about how Docker worked until today. Even less about Postgres. Took me forever to figure out how to connect to a Postgres database inside of a Docker container.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Highlander1694 picture Highlander1694  路  3Comments

cwanja picture cwanja  路  3Comments

bastrik picture bastrik  路  3Comments

JakobLichterfeld picture JakobLichterfeld  路  6Comments

kongomongo picture kongomongo  路  5Comments