I'm getting an error that I'm exceeding the number of requests allowed per session (30) when using this query (using Include instead of Customize):
ApplicationServer appServer = QuerySingleResultAndSetEtag(session => session
.Include<ApplicationServer>(x => x.CustomVariableGroupIds)
.Include<ApplicationServer>(x => x.ApplicationIdsForAllAppWithGroups)
.Include<ApplicationServer>(x => x.CustomVariableGroupIdsForAllAppWithGroups)
.Include<ApplicationServer>(x => x.CustomVariableGroupIdsForGroupsWithinApps)
.Include<ApplicationServer>(x => x.InstallationEnvironmentId)
.Load <ApplicationServer>(id))
as ApplicationServer;
Note, the error occurs on this line, which is called for each AppWithGroup within an application:
appGroup.Application = QuerySingleResultAndSetEtag(session =>
session.Load<Application>(appGroup.ApplicationId)) as Application;
However, this query (using Customize) doesn't create extra requests:
ApplicationServer appServer = QuerySingleResultAndSetEtag(session =>
session.Query<ApplicationServer>()
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIds))
.Customize(x => x.Include<ApplicationServer>(y => y.ApplicationIdsForAllAppWithGroups))
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForAllAppWithGroups))
.Customize(x => x.Include<ApplicationServer>(y => y.CustomVariableGroupIdsForGroupsWithinApps))
.Customize(x => x.Include<ApplicationServer>(y => y.InstallationEnvironmentId))
.Where(server => server.Id == id).FirstOrDefault())
as ApplicationServer;
However, the above query causes an error:
Attempt to query by id only is blocked, you should use call
session.Load("applications/2017"); instead of
session.Query().Where(x=>x.Id == "applications/2017");
You can turn this error off by specifying
documentStore.Conventions.AllowQueriesOnId = true;, but that is not
recommend and provided for backward compatibility reasons only.
I had to set AllowQueriesOnId = true because it was the only way I could get this to work.
What am I doing wrong in the first query to cause the includes not to work?
By the way, another post had the same issue where he had to use Customize. I'd like to do this correctly though.
I'm not sure why the load isn't doing this for you, What version of raven are you on? I just tested this in Raven 2.5 build 2700 and the include is bringing back the information for me in a single request.
Anyway, with the load not working quite like i would expect, i would switch to a set of lazy queries to get what you want in 2 server round trips. http://ravendb.net/docs/2.5/client-api/querying/lazy-operations.
Another option that might work out better for you, (depending on what you are really doing with all of that data) is a transformer. http://ravendb.net/docs/2.5/client-api/querying/results-transformation/result-transformers?version=2.5
Hope that helps.
Related
I am building a WebDAV server using sabre/dav, I want to create a WebDAV server file storage location in Wasabi which is compatible with AmazonS3, I did some research and found something that looks like AWS.php but I don't know how to use it. If anyone knows how to do this specifically, please respond.
What we tried:
・Download s3dav (https://github.com/audionamix/s3dav) and install the file.
・Server.php was written as follows
<?php
use Sabre\DAV;
use Aws\S3\S3Client;
// The autoloader
require 'vendor/autoload.php';
$raw_credentials = array(
'credentials' => array(
'key' => '<insert-access-key>',
'secret' => '<insert-secret-key>'
),
//'profile' => 'wasabi',
'endpoint' => 'https://s3.wasabisys.com',
'region' => 'us-east-1',
'version' => 'latest',
'use_path_style_endpoint' => true,
'use_path_style' => true,
'use_ssl' => true,
'port' => 443,
'hostname' => 's3.wasabisys.com',
'bucket' => '<bucket-name>',
);
// establish an S3 Client.
$s3 = S3Client::factory($raw_credentials);
// Now we're creating a whole bunch of objects
//$rootDirectory = new DAV\FS\Directory('public');
$rootDirectory = new DAV\FS\S3Directory("/",'<bucket-name>',$s3);
// The server object is responsible for making sense out of the WebDAV protocol
$server = new DAV\Server($rootDirectory);
// If your server is not on your webroot, make sure the following line has the
// correct information
$server->setBaseUri('/server.php/');
// The lock manager is reponsible for making sure users don't overwrite
// each others changes.
$lockBackend = new DAV\Locks\Backend\File('data/locks');
$lockPlugin = new DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// This ensures that we get a pretty index in the browser, but it is
// optional.
$server->addPlugin(new DAV\Browser\Plugin());
// All we need to do now, is to fire up the server
$server->exec();
Result:
The file name list is displayed, but it is displayed as 0 bytes.
Uploading is working, but other operations are not working (file size is correct on Wasabi).
”4.4.0 Exception Cannot traverse an already closed generator" is displayed.
I am trying to implement slugs in my bundle, but when i try to create a record and run my message consumer i get the following error:
Unexpected exception occurred during Direct URL generation ["exception" => Oro\Bundle\RedirectBundle\Exception\UnsupportedEntityException { …}] ["processor" => "Oro\Bundle\RedirectBundle\Async\DirectUrlProcessor","message_id" => "oro.6256de2124b630.96491198","message_body" => ["createRedirect" => true,"id" => [3],"class" => "Phpro\OroBundleBlogBundle\Entity\BlogPostCategory"],"message_properties" => ["oro.message_queue.client.topic_name" => "oro.redirect.generate_direct_url.entity","oro.message_queue.client.queue_name" => "oro.default","oro.security.token" => "organizationId=1;userId=1;userClass=Oro\Bundle\UserBundle\Entity\User;roles=ROLE_ADMINISTRATOR"],"message_headers" => ["content_type" => "application/json","message_id" => "oro.6256de2124b630.96491198","timestamp" => "1649860129","priority" => "2"],"elapsed_time" => "34 ms","memory_usage" => "107.57 MB"]
The slugs are stored, but the use of the get_slug_urls_for_prototypes twig filter results in the following error An exception has been thrown during the rendering of a template (""). Again because of the UnsupportedEntityException
Am i missing some configuration?
As mentioned in the OroCommerce documentation the entity must implement the interface to support slugs. Make sure you fulfilled this requirement.
I migrating from EF core 2.2 to 3.1 and a query that used to work, now throws an exception .
I know that there are breaking changes to this version but I need to find a proper workaround for my query, hope someone could help :)
The query:
return await dbContext.JobsBulkDbSet.Where(i => i.Uuid == uuid)
.GroupJoin(dbContext.JobDbSet.Include(x => x.UpgradeJobs),
bulk => bulk.Uuid,
job => job.JobsBulkEntityUuid,
(bulk, jobs) => SetJobs(bulk, jobs)).AsNoTracking().FirstOrDefaultAsync();
And the error I get is :
Processing of the LINQ expression 'DbSet<JobsBulkEntity>
.Where(i => i.Uuid == __uuid_0)
.GroupJoin(
outer: DbSet<JobEntity>
.Include(x => x.UpgradeJobs),
inner: bulk => bulk.Uuid,
outerKeySelector: job => job.JobsBulkEntityUuid,
innerKeySelector: (bulk, jobs) => EFJobsBulkRepository.SetJobs(
bulk: bulk,
jobs: jobs))' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
Thanks
I am trying to implement controller integration testing in CakePHP 3.6 using its testing tools. I assumed that this would be handled by making a 'real' (as in CURL) HTTP request against the running webserver, but it looks like it isn't. Below is the test case code I'm using.
The problems I'm running into:
The test case is somehow managing to access the controler action,
even when the webserver is not running at all (Apache down and no
dev webserver running).
When running this test, the controller does not have access to
$_SERVER (see below) and any of the $postData defined in the test case appears empty on the controller side.
When I place exit; in the controller code, the whole test case
stops, which suggests that the controller code is run directly, not
via a HTTP request.
Question: How can I make a 'real' HTTP requests when testing controllers, apart from resorting to using CURL and handling the requests manually?
Clearly, I am either not understanding how the controller testing is done, or I'm doing something wrong.
Test case I'm using:
/tests/TestCase/Controller/JobsControllerTest.php
<?php
namespace App\Test\TestCase\Controller;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
/**
* App\Controller\JobsController Test Case
*/
class JobsControllerTest extends IntegrationTestCase
{
/**
* Test add method
*
* #return void
*/
public function testAdd()
{
$this->useHttpServer(true);
$this->configRequest([
'headers' => [
'Content-Type' => 'application/json',
'X-Api-Key' => '8f083c8f083c8f083c8f083c'
]
]);
$postData = [
'user_id' => 3,
'job_status' => 'New'
];
$this->post('/jobs/add', $postData);
$this->assertResponseSuccess();
$jobs = TableRegistry::get('Jobs');
$query = $jobs->find()->where(['user_id' => $postData['user_id']]);
$this->assertEquals(1, $query->count());
}
}
The dump of $_SERVER global from the controller that I'm testing:
Array
(
[LS_COLORS] => rs=0:di=01;34 [...]
[LANG] => en_US.UTF-8
[HOME] => /home/tomasz
[TERM] => screen
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
[MAIL] => /var/mail/root
[LOGNAME] => root
[USER] => root
[USERNAME] => root
[SHELL] => /bin/bash
[SUDO_COMMAND] => vendor/bin/phpunit --verbose
[SUDO_USER] => tomasz
[SUDO_UID] => 1000
[SUDO_GID] => 1000
[PHP_SELF] => vendor/bin/phpunit
[SCRIPT_NAME] => vendor/bin/phpunit
[SCRIPT_FILENAME] => vendor/bin/phpunit
[PATH_TRANSLATED] => vendor/bin/phpunit
[DOCUMENT_ROOT] =>
[REQUEST_TIME_FLOAT] => 1546631688.0758
[REQUEST_TIME] => 1546631688
[argv] => Array
(
[0] => vendor/bin/phpunit
[1] => --verbose
)
[argc] => 2
)
CakePHP integration tests do not issue actual HTTP requests, they simulate them, it's very fast, allows for certain mocking, inspecting session contents, accessing exception details, etc., all sorts of things that wouldn't really be possible (at least not easily) when using real HTTP requests. If you really need to issue actual requests, then you should look into using other utilities, like for example Codeception (specifically acceptance tests).
When using CakePHP, it is advised that you do not access PHP superglobals directly, but that you retrieve the data from the abstracted APIs provided by CakePHP! Breaking your integration tests is one of the reasons for this. The simulated request will receive a request object that has been prepared with the data from your test case, that is where you need to look it up.
For example if you want to access POST data in your app, maybe in your controller, then you do it like this:
$user_id = $this->request->getData('user_id');
See also
Cookbook > Testing > Controller Integration Testing
Cookbook > Request & Response Objects
I'm working with rails to create a client for the Fitbit API (very similar to twitter api) on Rails.
In my device.rb file
def fitbit_data
#client = Fitgem::Client.new (
:consumer_key => 'bb1', #I understand the security issues here and will change it for production
:consumer_secret => '81f',
:token => oauth_token,
:secret => oauth_token_secret,
:user_id => uid
)
end
It says that my syntax is wrong and asks for a ')' after :consumer_key. How do I get the syntax correct?
Note: this answer is applicable for Rails 4.1.4 and Fitgem 0.10.0.
I think the issue here is that to initialize a client, you have to pass in a hash. Additionally, I do not believe it's necessary to specify a user_id key. See my code below:
$client = Fitgem::Client.new ({ :consumer_key => ENV["FITBIT_CONSUMER_KEY"],
:consumer_secret => ENV["FITBIT_CONSUMER_SECRET"],
:token => ENV["OAUTH_TOKEN"],
:secret => ENV["OAUTH_SECRET"] })
Let me know if this helps.