threefoldtecharchive / jumpscaleX_archived

Apache License 2.0
1 stars 6 forks source link

model.new should raise error if it already exists #713

Closed rkhamis closed 5 years ago

serboctor commented 5 years ago

That is already the case, unless if the instance that was created first was not saved.

JSX> j.servers.sonic.new(name='testerror')                                                                                                                                                            
## sonicserver SonicServer

### properties:
 - config_path          : /sandbox/cfg/sonic_config.cfg
 - default_client       : 
 - startupcmd           : 

### data:
 - host                 : 127.0.0.1
 - name                 : testerror
 - password             : 123456
 - port                 : 1491
 - timeout              : 300

JSX> _.save()                                                                                                                                                                                               
## .sonic.server
id: 19
name                : testerror
host                : 127.0.0.1
port                : 1,491
password            : 123456
timeout             : 300

JSX> j.servers.sonic.new(name='testerror')                                                                                                                                                                  
Sun 14 16:47:54 _sonic_server_1.py - 340 - jumpscale.sonic.server.1:19        : DDICT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/sandbox/lib/jumpscale/Jumpscale/core/BASECLASSES/JSConfigs.py", line 73, in new
    raise RuntimeError("obj: %s already exists" % name)
RuntimeError: obj: testerror already exists

obj: testerror already exists
rkhamis commented 5 years ago

Indeed, this behavior makes sense