Declarative Authorization - Catch "Authorization::NotAuthorized" Exception - ruby-on-rails

I'm currently using Declarative Authorization on my application, and trying to catch Exceptions from type Authorization::NotAuthorized.
I have an Entity that has a category. Depending on the role a user can create a new category when creating this entity. At my :before_validation callback I assign the category and want to be able to catch the authorization exception in case he doesn't have permission.
I could check it's role and make a conditional instruction, but then would have to write all the roles.
Exception is being thrown, but I'm not able to catch it, at the "new" instruction.
Code follows:
# Model
before_validation :set_category
def category_name
#category_name ||= category.name unless category.nil?
#category_name
end
def category_name=(name)
name.strip!
name.downcase!
#category_name = name
end
def set_category
if #category_name and not company.blank?
lookup_category = company.categories.not_deleted.find_by_name(#category_name)
begin
category = lookup_category.blank? ? company.categories.new(:name => #category_name) : lookup_category
rescue Authorization::NotAuthorized
errors.add(:category, I18n.t('activerecord.errors.messages.exclusion'))
end
end
end
# Controller
def create
#ticket = current_user.created_tickets.new(params[:ticket])
if #ticket.save # Line 88
...
Exception stack trace:
Authorization::NotAuthorized (No matching rules found for create for #<User id: 36,..."> (roles [:Requester], privileges [:create], context :categories).):
/Library/Ruby/Gems/1.8/gems/declarative_authorization-0.4.1/lib/declarative_authorization/authorization.rb:168:in `permit!'
/Library/Ruby/Gems/1.8/gems/declarative_authorization-0.4.1/lib/declarative_authorization/in_model.rb:131:in `using_access_control'
/Library/Ruby/Gems/1.8/gems/after_commit-1.0.7/lib/after_commit/connection_adapters.rb:12:in `transaction'
/Library/Ruby/Gems/1.8/gems/after_commit-1.0.7/lib/after_commit/connection_adapters.rb:12:in `transaction'
app/controllers/tickets_controller.rb:88:in `create'
Debugger goes inside the block:
# Debugger
lookup_category = company.categories.not_deleted.find_by_name(#category_name)
(rdb:3) list
[275, 284] in /Users/Pedro/projects/trunk/app/models/ticket.rb
275
276 def set_category
277 if #category_name and not self.company.blank?
278 begin
279 debugger
=> 280 lookup_category = company.categories.not_deleted.find_by_name(#category_name)
281 self.category = lookup_category.blank? ? company.categories.new(:name => #category_name) : lookup_category
282 rescue Authorization::NotAuthorized
283 self.errors.add(:category, I18n.t('activerecord.errors.messages.exclusion'))
284 end
(rdb:3) n
/Users/Pedro/projects/trunk/app/models/ticket.rb:281
self.category = lookup_category.blank? ? company.categories.new(:name => #category_name) : lookup_category
(rdb:3) list
[276, 285] in /Users/Pedro/projects/trunk/app/models/ticket.rb
276 def set_category
277 if #category_name and not self.company.blank?
278 begin
279 debugger
280 lookup_category = company.categories.not_deleted.find_by_name(#category_name)
=> 281 self.category = lookup_category.blank? ? company.categories.new(:name => #category_name) : lookup_category
282 rescue Authorization::NotAuthorized
283 self.errors.add(:category, I18n.t('activerecord.errors.messages.exclusion'))
284 end
285 end
(rdb:3) n
/Users/Pedro/.gem/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:94
break result if terminator.call(result, object)
(rdb:3) list
[89, 98] in /Users/Pedro/.gem/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb
89 unless block_given?
90 send(enumerator) { |callback| callback.call(object) }
91 else
92 send(enumerator) do |callback|
93 result = callback.call(object)
=> 94 break result if terminator.call(result, object)
95 end
96 end
97 end
98
(rdb:3)

I'd say that it's breaking outside the begin ... rescue block and therefore not caught by the rescue. Try to do the same rescue on line 88 of your controller.
If you want to handle this in the validation process, maybe try to do a test on the roles or permissions of the user before creating your object instead of catching the exception that will only be thrown on creation.

It's not possible to catch the exception on a before callback. The best way I found to do this kind of validation is:
# Model code
begin
User.with_permissions_to :create, :categories # Raises exception if not permitted
... do whatever you want
rescue
... do whatever you want
end
Thanks for all the help

Related

load_from_checkpoint fails after transfer learning a LightningModule

I try to transfer learn a LightningModule. The relevant part of the code is this:
class DeepFilteringTransferLearning(pl.LightningModule):
def __init__(self, chk_path = None):
super().__init__()
#init class members
self.prediction = []
self.label = []
self.loss = MSELoss()
#init pretrained model
self.chk_path = chk_path
model = DeepFiltering.load_from_checkpoint(chk_path)
backbone = model.sequential
layers = list(backbone.children())[:-1]
self.groundModel = Sequential(*layers)
#use the pretrained modell the same way to regress Lshall and neq
self.regressor = nn.Linear(64,2)
def forward(self, x):
self.groundModel.eval()
with torch.no_grad():
groundOut = self.groundModel(x)
yPred = self.regressor(groundOut)
return yPred
I save my model in a different, main file which relevant part is:
#callbacks
callbacks = [
ModelCheckpoint(
dirpath = "checkpoints/maxPooling16StandardizedL2RegularizedReproduceableSeeded42Ampl1ConvTransferLearned",
save_top_k=5,
monitor="val_loss",
),
]
#trainer
trainer = pl.Trainer(gpus=[1,2],strategy="dp",max_epochs=150,logger=wandb_logger,callbacks=callbacks,precision=32,deterministic=True)
trainer.fit(model,train_dataloaders=trainDl,val_dataloaders=valDl)
After try to load the modell from checkpoint like this:
chk_patH = "path/to/transfer_learned/model"
standardizedL2RegularizedL1 = DeepFilteringTransferLearning("path/to/model/trying/to/use/for/transfer_learning").load_from_checkpoint(chk_patH)
I got the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in _check_seekable(f)
307 try:
--> 308 f.seek(f.tell())
309 return True
AttributeError: 'NoneType' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-6-13f5fd0c7b85> in <module>
1 chk_patH = "checkpoints/maxPooling16StandardizedL2RegularizedReproduceableSeeded42Ampl1/epoch=4-step=349.ckpt"
----> 2 standardizedL2RegularizedL1 = DeepFilteringTransferLearning("checkpoints/maxPooling16StandardizedL2RegularizedReproduceableSeeded42Ampl2/epoch=145-step=10219.ckpt").load_from_checkpoint(chk_patH)
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/pytorch_lightning/core/saving.py in load_from_checkpoint(cls, checkpoint_path, map_location, hparams_file, strict, **kwargs)
154 checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].update(kwargs)
155
--> 156 model = cls._load_model_state(checkpoint, strict=strict, **kwargs)
157 return model
158
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/pytorch_lightning/core/saving.py in _load_model_state(cls, checkpoint, strict, **cls_kwargs_new)
196 _cls_kwargs = {k: v for k, v in _cls_kwargs.items() if k in cls_init_args_name}
197
--> 198 model = cls(**_cls_kwargs)
199
200 # give model a chance to load something
~/whistlerProject/gitHub/whistler/mathe/gwInspired/deepFilteringTransferLearning.py in __init__(self, chk_path)
34 #init pretrained model
35 self.chk_path = chk_path
---> 36 model = DeepFiltering.load_from_checkpoint(chk_path)
37 backbone = model.sequential
38 layers = list(backbone.children())[:-1]
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/pytorch_lightning/core/saving.py in load_from_checkpoint(cls, checkpoint_path, map_location, hparams_file, strict, **kwargs)
132 checkpoint = pl_load(checkpoint_path, map_location=map_location)
133 else:
--> 134 checkpoint = pl_load(checkpoint_path, map_location=lambda storage, loc: storage)
135
136 if hparams_file is not None:
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/pytorch_lightning/utilities/cloud_io.py in load(path_or_url, map_location)
31 if not isinstance(path_or_url, (str, Path)):
32 # any sort of BytesIO or similiar
---> 33 return torch.load(path_or_url, map_location=map_location)
34 if str(path_or_url).startswith("http"):
35 return torch.hub.load_state_dict_from_url(str(path_or_url), map_location=map_location)
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
579 pickle_load_args['encoding'] = 'utf-8'
580
--> 581 with _open_file_like(f, 'rb') as opened_file:
582 if _is_zipfile(opened_file):
583 # The zipfile reader is going to advance the current file position.
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in _open_file_like(name_or_buffer, mode)
233 return _open_buffer_writer(name_or_buffer)
234 elif 'r' in mode:
--> 235 return _open_buffer_reader(name_or_buffer)
236 else:
237 raise RuntimeError(f"Expected 'r' or 'w' in mode but got {mode}")
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in __init__(self, buffer)
218 def __init__(self, buffer):
219 super(_open_buffer_reader, self).__init__(buffer)
--> 220 _check_seekable(buffer)
221
222
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in _check_seekable(f)
309 return True
310 except (io.UnsupportedOperation, AttributeError) as e:
--> 311 raise_err_msg(["seek", "tell"], e)
312 return False
313
~/anaconda3/envs/skimageTrial/lib/python3.6/site-packages/torch/serialization.py in raise_err_msg(patterns, e)
302 + " Please pre-load the data into a buffer like io.BytesIO and"
303 + " try to load from it instead.")
--> 304 raise type(e)(msg)
305 raise e
306
AttributeError: 'NoneType' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
which I can't resolve.
I try to this according to the available tutorials on the official page of pytorch lightning here. I can't figure it out what I miss.
Could somebody point me in the right direction?

Neo4j visualization with py2neo: TypeError: 'LabelSetView' object is not callable

I am trying to follow the example in
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html
from scripts.vis import draw
import neo4jupyter
options = {"Person": "name", "Drink": "name", "Manufacturer": "name"}
draw(graph, options)
For this part of the code, I encounter this error:
ypeError Traceback (most recent call last)
<ipython-input-7-6a87e5426fa3> in <module>
3
4 options = {"Person": "name", "Drink": "name", "Manufacturer": "name"}
----> 5 draw(graph, options)
~\PycharmProjects\Knowledge_Graph\scripts\vis.py in draw(graph, options, physics, limit)
104 target_id = row[4]
105
--> 106 source_info = get_vis_info(source_node, source_id)
107
108 if source_info not in nodes:
~\PycharmProjects\Knowledge_Graph\scripts\vis.py in get_vis_info(node, id)
91
92 def get_vis_info(node, id):
---> 93 node_label = list(node.labels())[0]
94 prop_key = options.get(node_label)
95 vis_label = node.properties.get(prop_key, "")
TypeError: 'LabelSetView' object is not callable
I read online that there might be some issues with scripts.vis but I am not too sure how to resolve it
Please checkout the latest version from the below link and it fixes the problem
https://github.com/merqurio/neo4jupyter/issues/5

neo4django with Neo4j 2.0

I'm just starting out using Neo4j and I'd like to use 2.0 (I have 2.0.1 community installed). I see that neo4django was only tested against neo4j 1.8.2-1.9.4, but have people gotten it working with 2.x? I installed the gremlin plugin but can't create or query through neo4django.
create:
In [8]: NeoProfile.objects.create(profile_id=1234)
[INFO] requests.packages.urllib3.connectionpool#214: Resetting dropped connection: localhost
---------------------------------------------------------------------------
StatusException Traceback (most recent call last)
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 NeoProfile.objects.create(profile_id=1234)
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/manager.pyc in create(self, **kwargs)
41
42 def create(self, **kwargs):
---> 43 return self.get_query_set().create(**kwargs)
44
45 def filter(self, *args, **kwargs):
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/query.pyc in create(self, **kwargs)
1295 if 'id' in kwargs or 'pk' in kwargs:
1296 raise FieldError("Neo4j doesn't allow node ids to be assigned.")
-> 1297 return super(NodeQuerySet, self).create(**kwargs)
1298
1299 #TODO would be awesome if this were transactional
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/db/models/query.pyc in create(self, **kwargs)
375 obj = self.model(**kwargs)
376 self._for_write = True
--> 377 obj.save(force_insert=True, using=self.db)
378 return obj
379
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in save(self, using, **kwargs)
315
316 def save(self, using=DEFAULT_DB_ALIAS, **kwargs):
--> 317 return super(NodeModel, self).save(using=using, **kwargs)
318
319 #alters_data
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using)
461 if force_insert and force_update:
462 raise ValueError("Cannot force both insert and updating in model saving.")
--> 463 self.save_base(using=using, force_insert=force_insert, force_update=force_update)
464
465 save.alters_data = True
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in save_base(self, raw, cls, origin, force_insert, force_update, using, *args, **kwargs)
331
332 is_new = self.id is None
--> 333 self._save_neo4j_node(using)
334 self._save_properties(self, self.__node, is_new)
335 self._save_neo4j_relationships(self, self.__node)
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in _save_neo4j_node(self, using)
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in trans_method(func, *args, **kw)
95 #TODO this is where generalized transaction support will go,
96 #when it's ready in neo4jrestclient
---> 97 ret = func(*args, **kw)
98 #tx.commit()
99 return ret
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in _save_neo4j_node(self, using)
359 self.__node = conn.gremlin_tx(script, types=type_hier_props,
360 indexName=self.index_name(),
--> 361 typesToIndex=type_names_to_index)
362 return self.__node
363
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/neo4jclient.pyc in gremlin_tx(self, script, **params)
177 will be wrapped in a transaction.
178 """
--> 179 return self.gremlin(script, tx=True, **params)
180
181 def cypher(self, query, **params):
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/neo4jclient.pyc in gremlin(self, script, tx, raw, **params)
166 try:
167 return send_script(include_unloaded_libraries(lib_script),
--> 168 params)
169 except LibraryCouldNotLoad:
170 if i == 0:
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/neo4jclient.pyc in send_script(s, params)
151 if raw:
152 execute_kwargs['returns'] = RETURNS_RAW
--> 153 script_rv = ext.execute_script(s, params=params, **execute_kwargs)
154 if isinstance(script_rv, basestring):
155 if LIBRARY_ERROR_REGEX.match(script_rv):
/Users/atomos/workspace/Project-Vitamin/src/neo4j-rest-client/neo4jrestclient/client.py in __call__(self, *args, **kwargs)
2313 except (ValueError, AttributeError, KeyError, TypeError):
2314 pass
-> 2315 raise StatusException(response.status_code, msg)
2316
2317 def __repr__(self):
StatusException: Code [400]: Bad Request. Bad request syntax or unsupported method.
Invalid data sent: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException.setMaxBufferSize() is applicable for argument types: () values: []
query:
In [9]: NeoProfile.objects.filter(profile_id=1234)
Out[9]: ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 NeoProfile.objects.filter(profile_id=1234)
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
236 self.start_displayhook()
237 self.write_output_prompt()
--> 238 format_dict = self.compute_format_data(result)
239 self.write_format_data(format_dict)
240 self.update_user_ns(result)
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
148 MIME type representation of the object.
149 """
--> 150 return self.shell.display_formatter.format(result)
151
152 def write_format_data(self, format_dict):
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
124 continue
125 try:
--> 126 data = formatter(obj)
127 except:
128 # FIXME: log the exception
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
445 type_pprinters=self.type_printers,
446 deferred_pprinters=self.deferred_printers)
--> 447 printer.pretty(obj)
448 printer.flush()
449 return stream.getvalue()
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
358 if callable(meth):
359 return meth(obj, self, cycle)
--> 360 return _default_pprint(obj, self, cycle)
361 finally:
362 self.end_group()
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
478 if getattr(klass, '__repr__', None) not in _baseclass_reprs:
479 # A user-provided repr.
--> 480 p.text(repr(obj))
481 return
482 p.begin_group(1, '<')
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/db/models/query.pyc in __repr__(self)
70
71 def __repr__(self):
---> 72 data = list(self[:REPR_OUTPUT_SIZE + 1])
73 if len(data) > REPR_OUTPUT_SIZE:
74 data[-1] = "...(remaining elements truncated)..."
/Users/atomos/workspace/Project-Vitamin/lib/python2.7/site-packages/django/db/models/query.pyc in __len__(self)
85 self._result_cache = list(self.iterator())
86 elif self._iter:
---> 87 self._result_cache.extend(self._iter)
88 if self._prefetch_related_lookups and not self._prefetch_done:
89 self._prefetch_related_objects()
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/query.pyc in iterator(self)
1274 using = self.db
1275 if not self.query.can_filter():
-> 1276 for model in self.query.execute(using):
1277 yield model
1278 else:
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/query.pyc in execute(self, using)
1161 conn = connections[using]
1162
-> 1163 groovy, params = self.as_groovy(using)
1164
1165 raw_result_set = conn.gremlin_tx(groovy, **params) if groovy is not None else []
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/query.pyc in as_groovy(self, using)
925 # add the typeNodeId param, either for type verification or initial
926 # type tree traversal
--> 927 cypher_params['typeNodeId'] = self.model._type_node(using).id
928
929 type_restriction_expr = """
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in _type_node(cls, using)
411 return cls.__type_node_memoized(using)
412 else:
--> 413 return cls.__type_node_classmethod(using)
414
415 #classmethod
/Users/atomos/workspace/Project-Vitamin/src/neo4django/neo4django/db/models/base.pyc in __type_node(cls, using)
394 script_rv = conn.gremlin_tx(script, types=type_hier_props)
395 except Exception, e:
--> 396 raise RuntimeError(error_message, e)
397 if not hasattr(script_rv, 'properties'):
398 raise RuntimeError(error_message + '\n\n%s' % script_rv)
RuntimeError: ('The type node for class NeoProfile could not be created in the database.', StatusException())
My model is incredibly complex:
class NeoProfile(neomodels.NodeModel):
profile_id = neomodels.IntegerProperty(indexed=True)

How to arrange this pixel address one by one?

I am doing map processing. I solved the maze and got the address of the turnings. Below is my result.
(28,136)
(122,136)
(344,391)
(548,493)
(548,191)
(344,191)
(122,391)
But the addresses are not in correct order. My expected output is:
28 136
122 136
122 391
344 391
344 191
548 191
549 493
MY program is below. I programmed to get direction also
for(i=1:tblob)
if (shape(i).order==1)
map(i).cen=shape(i).cen;
end
end
White=[255 255 255];
i=1;
order=1;
left=0;
right=0;
up=0;
down=0;
left(1)=0;
right(1)=0;
up(1)=0;
down(1)=0;
left(2)=0;
right(2)=0;
up(2)=0;
down(2)=0;
left(3)=0;
right(3)=0;
up(3)=0;
down(3)=0;
left(4)=0;
right(4)=0;
up(4)=0;
down(4)=0;
left(5)=0;
right(5)=0;
up(5)=0;
down(5)=0;
left(6)=0;
right(6)=0;
up(6)=0;
down(6)=0;
left(7)=0;
right(7)=0;
up(7)=0;
down(7)=0;
left(8)=0;
right(8)=0;
up(8)=0;
down(8)=0;
x=map(i).cen(1,:);
y=map(i).cen(2,:);
for(z=1:100)
xi=x+1;
xj=x-1;
yi=y+1;
yj=y-1;
colorvalxi=color(y,xi,RGB);
colorvalxi
colorvalxj=color(y,xj,RGB);
colorvalxj
colorvalyi=color(yi,x,RGB);
colorvalyi
colorvalyj=color(yj,x,RGB);
colorvalyj
if(i>1)
s=i-1;
else
s=1;
end
if (left(s)==0)
if(colorvalxi==White)
n=1;
end
else
if (right(s)==0)
if(colorvalxj==White)
n=2;
end
else
if(up(s)==0)
if (colorvalyi==White)
n=3;
end
else
if(down(s)==0)
if(colorvalyj==White)
n=4;
end
else
break;
end
end
end
end
switch(n)
case 1 %RIGHT
for(ks=1:1000)
color_val=color(y,x,RGB);
if(color_val==White)
x=x+1;
else
right(i)=1;
instruction(i)=1;
i=i+1;
x=x-1;
map(i).cen(1,1)=x;
map(i).cen(2,1)=y;
break;
end
end
case 2 %LEFT
for(ks=1:1000)
color_val==color(y,x,RGB)
if(color_val==White)
x=x-1;
else
left(i)=1;
instruction(i)=2;
i=i+1;
x=x+1;
map(i).cen(1,1)=x;
map(i).cen(2,1)=y;
break;
end
end
case 3 %DOWN
for(ks=1:1000)
color_val=color(y,x,RGB);
if(color_val==White)
y=y+1;
else
down(i)=1;
instruction(i)=3;
i=i+1;
y=y-1;
map(i).cen(1,1)=x;
map(i).cen(2,1)=y;
break;
end
end
case 4 %UPWARD
for(ks=1:1000)
color_val=color(y,x,RGB);
if(color_val==White)
y=y-1;
else
up(i)=1;
instruction(i)=4;
i=i+1;
y=y-1;
map(i).cen(1,1)=x;
map(i).cen(2,1)=y;
break;
end
end
end
end

Strange symfony i18n error

I use symfony 1.4.11. In my site I have 3 languages in my site "se","en","no". In my backend, I use only en, and I have in settings:
all:
.settings:
default_culture: en
But in some module, when in frontend I have "se" language, have error :
Data file for "se" was not found.
In frontend I try, make i18n with database;
Stack trace:
stack trace
at ()
in SF_SYMFONY_LIB_DIR/i18n/sfCultureInfo.class.php line 301 ...
if (is_file($filename) == false)
{
throw new sfException(sprintf('Data file for "%s" was not found.', $file));
}
if (in_array($filename, $this->dataFiles) == false)
at sfCultureInfo->loadCultureData('se')
in SF_SYMFONY_LIB_DIR/i18n/sfCultureInfo.class.php line 217 ...
at sfCultureInfo->__construct('se')
in SF_SYMFONY_LIB_DIR/i18n/sfCultureInfo.class.php line 136 ...
at sfCultureInfo::getInstance('se')
in SF_SYMFONY_LIB_DIR/i18n/sfDateTimeFormatInfo.class.php line 186 ...
at sfDateTimeFormatInfo::getInstance('se')
in SF_SYMFONY_LIB_DIR/i18n/sfDateFormat.class.php line 100 ...
at sfDateFormat->__construct('se')
in SF_SYMFONY_LIB_DIR/helper/DateHelper.php line 57 ...
at format_date('2011-07-22 01:36:02', 'f')
in SF_ROOT_DIR/cache/backend/dev/modules/autoSfGuardUser/templates/_list_td_tabular.php line 5 ...
at require('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/_list_td_tabular.php')
in SF_SYMFONY_LIB_DIR/view/sfPHPView.class.php line 75 ...
at sfPHPView->renderFile('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/_list_td_tabular.php')
in SF_SYMFONY_LIB_DIR/view/sfPartialView.class.php line 124 ...
at sfPartialView->render()
in SF_SYMFONY_LIB_DIR/helper/PartialHelper.php line 218 ...
at get_partial('sfGuardUser/list_td_tabular', array('sf_guard_user' => object('sfOutputEscaperIteratorDecorator')))
in SF_SYMFONY_LIB_DIR/helper/PartialHelper.php line 180 ...
at include_partial('sfGuardUser/list_td_tabular', array('sf_guard_user' => object('sfOutputEscaperIteratorDecorator')))
in SF_ROOT_DIR/cache/backend/dev/modules/autoSfGuardUser/templates/_list.php line 31 ...
at require('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/_list.php')
in SF_SYMFONY_LIB_DIR/view/sfPHPView.class.php line 75 ...
at sfPHPView->renderFile('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/_list.php')
in SF_SYMFONY_LIB_DIR/view/sfPartialView.class.php line 124 ...
at sfPartialView->render()
in SF_SYMFONY_LIB_DIR/helper/PartialHelper.php line 218 ...
at get_partial('sfGuardUser/list', array('pager' => object('sfOutputEscaperIteratorDecorator'), 'sort' => object('sfOutputEscaperArrayDecorator'), 'helper' => object('sfGuardUserGeneratorHelper')))
in SF_SYMFONY_LIB_DIR/helper/PartialHelper.php line 180 ...
at include_partial('sfGuardUser/list', array('pager' => object('sfOutputEscaperIteratorDecorator'), 'sort' => object('sfOutputEscaperArrayDecorator'), 'helper' => object('sfGuardUserGeneratorHelper')))
in SF_ROOT_DIR/cache/backend/dev/modules/autoSfGuardUser/templates/indexSuccess.php line 19 ...
at require('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/indexSuccess.php')
in SF_SYMFONY_LIB_DIR/view/sfPHPView.class.php line 75 ...
at sfPHPView->renderFile('/home/dan/WEB/www/europellets-dev.my/cache/backend/dev/modules/autoSfGuardUser/templates/indexSuccess.php')
in SF_SYMFONY_LIB_DIR/view/sfPHPView.class.php line 185 ...
at sfPHPView->render()
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 155 ...
at sfExecutionFilter->executeView('sfGuardUser', 'index', 'Success', array('configuration' => object('sfGuardUserGeneratorConfiguration'), 'helper' => object('sfGuardUserGeneratorHelper'), 'filters' => object('sfGuardUserFormFilter'), 'pager' => object('sfDoctrinePager'), 'sort' => array(null, null)))
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 116 ...
at sfExecutionFilter->handleView(object('sfFilterChain'), object('sfGuardUserActions'), 'Success')
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 47 ...
at sfExecutionFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/filter/sfRenderingFilter.class.php line 33 ...
at sfRenderingFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/controller/sfController.class.php line 238 ...
at sfController->forward('sfGuardUser', 'index')
in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 48 ...
at sfFrontWebController->dispatch()
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 170 ...
at sfContext->dispatch()
in SF_ROOT_DIR/web/backend_dev.php line 13 ...
This error means that there is no ICU data file inside SF_SYMFONY_LIB_DIR/i18n/data/ dir for the 'se' culture. Symfony supports many cultures, but not all. In your case, if 'se' is Swedish - use 'sv' code.
sv sv-SE Swedish
sv-FI sv-FI Swedish (Finland)
sv-SE sv-SE Swedish (Sweden)
If 'se' is not Swedish and it is not in out of the box list (see SF_SYMFONY_LIB_DIR/i18n/data/ dir) - use internal tokens instead of pattern (e.g. format_date($date, 'f') -> format_date($date, 'd MMMM YYYY, hh:mm')) formatDateHowTo

Resources