Validation returning “ Undefined index”, because the context data is lost? - cakephp-3.0

I have the below code, it keeps giving me payment_method_id “ Undefined index" error, so I check the debug.log file, it shows
2017-11-18 00:27:39 Debug: 7
2017-11-18 00:27:40 Debug:
it seems that the validation method is called 2 times, and the first time the $context['data'][payment_method_id] is there, but after that, the second time, it is no longer there? anyone knows how to solve this problem? thanks
$validator->notEmpty('cc_expires', __('This field is required'),
function ($context) {
Log::write('debug', $context['data'][payment_method_id]);
if ($context ['data'] ['payment_method_id'] == 1 )
{
return true;
}}
);

Related

Mongo DB Error while Updating - error on remote shard - caused by cursor id

I have about 8 Million Documents in my Collection.
And I want to remove the special Characters in one of the fields.
I will post my Statement below.
I am using the mongo shell in the Mongo db compass tool.
The update is working about 30-50 Minutes and then throws the following error:
MongoServerError: Error on remote shard thisisjustforstack.com:27000 :: caused by :: cursor id 1272890412590646833 not found
I also see that after throwing this error, he did not update all documents.
db.getCollection('TEST_Collection').aggregate(
[{
$match: {
'1List.Comment': {
$exists: true
}
}
}, {
$project: {
'1List.Comment': 1
}
}]
)
.forEach(function(doc,Index) {doc.1List.Comment=doc.1List.Comment.replace(/[^a-zA-Z 0-9 ]/g, '');
db.TEST_Collection.updateMany({ "_id": doc._id },{ "$set": { "1List.Comment": doc.1List.Comment } });})
Can somebody please help to get this update statement working without running in some sort of timeout? I have read something about noCursorTimeout() but I am not sure on how to use it with my statement and using it in the shell.
Thank you all!
Cursor timeout can't be disabled on individual aggregation cursors.
But you can set on global config:
mongod --setParameter cursorTimeoutMillis=3600000 #1 hour
Anyway I think dividing the task in small batches is a better option

Python/JSON : I want to go to a specific thing when it can't find it in a json file

I'm actually making my discord bot and I wanted to make a command to know plane informations. I made it but know i want to put plane photos depending on the company.
I tried to do that:
if plane_data["data"][f"{flight_companie}"] == "FedEx" or "Ryanair" or "SWISS" or "Air France" or "SWISS" or "British Airways":
plane_photo = plane_data["data"][flight_companie]
else:
plane_photo = plane_data["data"]["unknown"]
Unknown is equal to a url photo that says there is no plane photos.
When i try with UPS it gives me that out:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'UPS Airlines'
Please help me out!!
if plane_data["data"][f"{flight_companie}"] == "FedEx" or "Ryanair"...
will always evaluate to True. This is because a string like "Ryanair" is truthy. Meaning it becomes true when converted to a boolean. So your line is equivialent to
if plane_data["data"][f"{flight_companie}"] == "FedEx" or True or True or True ...
or can not be used in this situation. I would use
if plane_data["data"][f"{flight_companie}"] in ["FedEx","Ryanair","SWISS","Air France","SWISS","British Airways"]:
instead.

Doing a search with Where and possibly all in rails

I'm working on a rails project that has two models - incoming_purchases and item_instances. An incoming purchase has many item_instances and an item_instance belongs to an incoming purchase. My problem is that I want to show all orders that have been received and to do this, each item_instance has to be received off the order. The item_instance model has a date_received column. So I can have an order, lets call 1.
Order 1: has two item instances where one of the items has been received:
item 1: date_received: 9/15/20
item 2: date_recieved: nil
I need to show records where ever value of date received is filled in order for the order to be received. Thus, the example above would not be received. So far, I have a scope written that looks like this:
scope :search_for_received_orders, ->{ joins(:item_instances).where.not('item_instances.date_received': [nil] ).distinct }
This would get me the example above which would be a partially filled order. My code to see NOT received orders WORKS and is this:
scope :search_for_not_received_orders, ->{ joins(:item_instances).where('item_instances.date_received': [nil, ""] ).distinct }
Basically, I need to ensure for a received order that ALL Item Instances have a date in the date_received column. I cannot figure this out. Thank you for any help.
Error I'm getting with first response below:
/home/mcuddy/learn/inventory/src/inventory/app/models/incoming_purchase.rb:23: syntax error, unexpected '}', expecting => ...nces: {!date_received.present?})} ... ^
/home/mcuddy/learn/inventory/src/inventory/app/models/incoming_purchase.rb:36: syntax error, unexpected do (for lambda) item_instances.each do |i| ^~
/home/mcuddy/learn/inventory/src/inventory/app/models/incoming_purchase.rb:40: syntax error, unexpected end, expecting '}' end ^~~
scope :received_orders, -> { includes(:item_instances).where.not(item_instances: {!date_received.present?})}
Try this:
scope :received_orders, -> { includes(:item_instances).where.not(item_instances: {date_received: nil})}
scope :not_received_orders, -> { includes(:item_instances).where(item_instances: {date_received: nil})}
Received orders don't have any item instance with date_received nil.
Not received orders have at least 1 item instance with date_received nil
Try following, also ref this for how to use where condition
scope :search_for_received_orders,
->{ joins(:item_instances)
.where.not('item_instances.date_received': nil).distinct }
scope :search_for_not_received_orders,
->{ joins(:item_instances)
.where("item_instances.date_received IS NULL OR item_instances.date_received = ''"}).distinct }

Sails js Unknown column 'NaN' in 'where clause'

My code has been working, but when I updated to sails 0.12.1, from 0.11 this issue started happening.
I have been through other similar posts, but to my understanding none fits into my issue and all suggested solutions are not an issue in my case. Especially since this worked before updated.
AngularController call:
$http.get('/getS',{
p_id: p.id,
limit: 5
})
...
And yes I have console.log() both the id and limit value, they are not NaN.
Routes (have tried both):
'GET /getS' : {controller: 'SController', action: 'getS', skipAssets:true},
'GET /getS' : 'SController.getS',
Controller: if I log the id and limit values they are NaN for some unknown reason. Also, req.allParams() shows empty.
getS: function(req, res){
var id = req.param('p_id');
var max = req.param('limit');
P_s.find()
.where({p_id:id})
.limit(max)
.sort('createdAt desc')
...
This is clearly not something I have done wrong, how can this be fixed?
I do multiple other http.gets, they all work. A potential difference though is that this http.get is done inside another http.gets response(.then{}).

I can't manage to create 3rd level of dijit.Tree

I wanted to create a 3 level dijit.Tree, like that:
-root
|
--level1
|
--level2
I thought it would be really simple since there's a code snippet in this tutorial (example 1). But somehow I manage to fail.
This is my dojo code (variable names are in Polish, I hope it's not a problem):
modelRaportow = new dijit.tree.ForestStoreModel({
store: new dojo.data.ItemFileReadStore({
url: "logika/getJSON/getStatusRaportow.php"
}),
query: {typ: 'galaz'},
rootId: 'statusRaportuRoot',
rootLabel: 'Status raportu',
childrenAttrs: 'raporty'
});
drzewoRaportow = new dijit.Tree({
openOnClick: true,
model: modelRaportow,
showRoot: true,
persist: false
}, "target-status-raportow");
drzewoRaportow.startup();
This is my JSON returned by logika/getJSON/getStatusRaportow.php (again, names are in Polish):
{
"identifier":"id",
"label":"status",
"items": [
{"id":0,"status":"zaakceptowane","typ":"galaz"
"raporty":[{"_reference":1},{"_reference":2},{"_reference":3}]},
{"id":1,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport0","typ":"lisc"},
{"id":2,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":1,"status":"Raport1","typ":"lisc"},
{"id":3,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport2","typ":"lisc"},
{"id":4,"status":"odrzucone","typ":"galaz"
"raporty":[{"_reference":5},{"_reference":6},{"_reference":7}]},
{"id":5,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":1,"status":"Raport3","typ":"lisc"},
{"id":6,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport4","typ":"lisc"},
{"id":7,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport5","typ":"lisc"}
]}
And finally, this is what I'm getting: img - root node and lvl 1 nodes returned by query, no child nodes.
The question is - where is my mistake? Can anyone see it?
You have no comma between the typ and raporty value pair.
I have a partial answer: by stepping through the code in a similar situation, I've discovered that it expects childrenAttrs to be an array, so it should be:
childrenAttrs: ['raporty']
but I still cannot get the third level to appear in my case.