New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoCollection: Save does not only write attributes #762

Closed
sebastianhelbig opened this Issue Apr 22, 2017 · 12 comments

Comments

Projects
None yet
6 participants
@sebastianhelbig

sebastianhelbig commented Apr 22, 2017

Behaviour

When creating a new MongoCollection object, setting a property and then saving it, all the private fields, and not only the attributes, are saved as well.

class User extends Phalcon\Mvc\MongoCollection
{
    public function getSource()
    {
        return 'users';
    }
}

$user = new User();
$user->name = 'Robert';
$user->save();

Result

2017-04-22 13-09-02

Expected

Only _id and name gets set in the document.

Versions

  • Phalcon Framework version: 3.1.2
  • Phalcon Incubator version: 3.1.1
  • PHP Version: 7.1.4
  • Operating System: OS X
  • Server: nginx

@sergeyklay sergeyklay added the Mongo label Apr 22, 2017

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Apr 27, 2017

Member

I wonder if the same happens for php5 and Phalcon\Mvc\Collection?

Member

Jurigag commented Apr 27, 2017

I wonder if the same happens for php5 and Phalcon\Mvc\Collection?

@tkroll

This comment has been minimized.

Show comment
Hide comment
@tkroll

tkroll May 2, 2017

@Jurigag Works fine for me

PHP 5.6.23
Phalcon 2.0.10
Mongo 3.0.14

tkroll commented May 2, 2017

@Jurigag Works fine for me

PHP 5.6.23
Phalcon 2.0.10
Mongo 3.0.14

@dereckmartin

This comment has been minimized.

Show comment
Hide comment
@dereckmartin

dereckmartin May 3, 2017

I have the same issue with PHP7.1, I didn't have this issue on PHP7.0

Phalcon + PHP

root@app:~# phalcon -v

Phalcon DevTools (3.1.2)

Environment::
  OS: Linux app 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64
  PHP Version: 7.1.4-1+deb.sury.org~xenial+1
  PHP SAPI: cli
  PHP Bin: /usr/bin/php7.1
  PHP Extension Dir: /usr/lib/php/20160303
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php/7.1/cli/php.ini
Versions::
  Phalcon DevTools Version: 3.1.2
  Phalcon Version: 3.1.2
  AdminLTE Version: 2.3.6

MongoDB

root@app:~# mongod --version
db version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

I even installed Mongo 2.6 that you can get from base Ubuntu repository, and I get the same issue:

root@app:~# mongod --version
db version v2.6.10
2017-05-02T21:39:54.552-0400 git version: nogitversion
2017-05-02T21:39:54.552-0400 OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016

I have the same issue with PHP7.1, I didn't have this issue on PHP7.0

Phalcon + PHP

root@app:~# phalcon -v

Phalcon DevTools (3.1.2)

Environment::
  OS: Linux app 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64
  PHP Version: 7.1.4-1+deb.sury.org~xenial+1
  PHP SAPI: cli
  PHP Bin: /usr/bin/php7.1
  PHP Extension Dir: /usr/lib/php/20160303
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php/7.1/cli/php.ini
Versions::
  Phalcon DevTools Version: 3.1.2
  Phalcon Version: 3.1.2
  AdminLTE Version: 2.3.6

MongoDB

root@app:~# mongod --version
db version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

I even installed Mongo 2.6 that you can get from base Ubuntu repository, and I get the same issue:

root@app:~# mongod --version
db version v2.6.10
2017-05-02T21:39:54.552-0400 git version: nogitversion
2017-05-02T21:39:54.552-0400 OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
@dereckmartin

This comment has been minimized.

Show comment
Hide comment
@dereckmartin

dereckmartin May 3, 2017

I can confirm downgrading to php7.0 resolves the issue:

> db.audit.find();
# On PHP-7.1
{ "_id" : ObjectId("590934b3d2a57d04c47873b8"), "ip" : "10.0.2.2", "uri" : "/api", "method" : "GET", "time" : 16.43, "version" : 1, "_dependencyInjector" : {  }, "_modelsManager" : {  }, "_source" : null, "_operationMade" : 1, "_dirtyState" : 1, "_connection" : {  }, "_errorMessages" : [ ], "_skipped" : false }

# On PHP-7.0
{ "_id" : ObjectId("590936d2d2a57d34117f45c2"), "ip" : "10.0.2.2", "uri" : "/api", "method" : "GET", "time" : 234.25, "version" : 1 }

PHP version

root@app:~# phalcon -v

Phalcon DevTools (3.1.2)

Environment::
  OS: Linux app 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64
  PHP Version: 7.0.18-1+deb.sury.org~xenial+1
  PHP SAPI: cli
  PHP Bin: /usr/bin/php7.0
  PHP Extension Dir: /usr/lib/php/20151012
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php/7.0/cli/php.ini
Versions::
  Phalcon DevTools Version: 3.1.2
  Phalcon Version: 3.1.2
  AdminLTE Version: 2.3.6

I can confirm downgrading to php7.0 resolves the issue:

> db.audit.find();
# On PHP-7.1
{ "_id" : ObjectId("590934b3d2a57d04c47873b8"), "ip" : "10.0.2.2", "uri" : "/api", "method" : "GET", "time" : 16.43, "version" : 1, "_dependencyInjector" : {  }, "_modelsManager" : {  }, "_source" : null, "_operationMade" : 1, "_dirtyState" : 1, "_connection" : {  }, "_errorMessages" : [ ], "_skipped" : false }

# On PHP-7.0
{ "_id" : ObjectId("590936d2d2a57d34117f45c2"), "ip" : "10.0.2.2", "uri" : "/api", "method" : "GET", "time" : 234.25, "version" : 1 }

PHP version

root@app:~# phalcon -v

Phalcon DevTools (3.1.2)

Environment::
  OS: Linux app 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64
  PHP Version: 7.0.18-1+deb.sury.org~xenial+1
  PHP SAPI: cli
  PHP Bin: /usr/bin/php7.0
  PHP Extension Dir: /usr/lib/php/20151012
  PHP Bin Dir: /usr/bin
  Loaded PHP config: /etc/php/7.0/cli/php.ini
Versions::
  Phalcon DevTools Version: 3.1.2
  Phalcon Version: 3.1.2
  AdminLTE Version: 2.3.6
@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag May 10, 2017

Member

Yea, it happens only for php 7.1, looks like zephir problem.

Member

Jurigag commented May 10, 2017

Yea, it happens only for php 7.1, looks like zephir problem.

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag May 10, 2017

Member

Well i have this even on php 7 for some reason. Like getReservedAttributes() just return null.

Member

Jurigag commented May 10, 2017

Well i have this even on php 7 for some reason. Like getReservedAttributes() just return null.

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag May 23, 2017

Member

This is zephir related bug - phalcon/zephir#1536

Actually it's php bug - https://bugs.php.net/bug.php?id=74648.

phalcon/cphalcon#12862 - here is workaround in phalcon for it.

Member

Jurigag commented May 23, 2017

This is zephir related bug - phalcon/zephir#1536

Actually it's php bug - https://bugs.php.net/bug.php?id=74648.

phalcon/cphalcon#12862 - here is workaround in phalcon for it.

@sebastianhelbig

This comment has been minimized.

Show comment
Hide comment
@sebastianhelbig

sebastianhelbig May 25, 2017

I use the suggestion here #760 (comment) as a workaround, seems to be the same problem?

I use the suggestion here #760 (comment) as a workaround, seems to be the same problem?

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Jun 12, 2017

Member

Also im not sure if i even understand this getReservedAttributes correctly, shouldn't it have ALL protected propertis from Phalcon\Mvc\Collection or Phalcon\Mvc\MongoCollection ? It looks like get_object_vars in zephir returns values inconsistent?

Yea, exactly - phalcon/zephir#1548 On php 5 and 7.0 get_object_vars, even called in class scope returns only public properties anyway.

Member

Jurigag commented Jun 12, 2017

Also im not sure if i even understand this getReservedAttributes correctly, shouldn't it have ALL protected propertis from Phalcon\Mvc\Collection or Phalcon\Mvc\MongoCollection ? It looks like get_object_vars in zephir returns values inconsistent?

Yea, exactly - phalcon/zephir#1548 On php 5 and 7.0 get_object_vars, even called in class scope returns only public properties anyway.

@Jurigag Jurigag referenced this issue Jun 12, 2017

Merged

Updated collection reserved attributes #12891

2 of 3 tasks complete
@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Jun 20, 2017

Member

In phalcon 3.2 it should be working fine right now.

Member

Jurigag commented Jun 20, 2017

In phalcon 3.2 it should be working fine right now.

@Jurigag Jurigag closed this Jun 20, 2017

@Jurigag

This comment has been minimized.

Show comment
Hide comment
@Jurigag

Jurigag Jun 20, 2017

Member

If someone still have problems #760 (comment) then read this comment and below.

Member

Jurigag commented Jun 20, 2017

If someone still have problems #760 (comment) then read this comment and below.

@aprchen

This comment has been minimized.

Show comment
Hide comment
@aprchen

aprchen Jan 31, 2018

I have some situation here, save can take effect, but the modification and deletion are not effective,
image
It turns out to be the same.
image
When I use the following method, the modification succeeds
image

MongoDB extension version => 1.3.4
php version =>7.1.11
MongoDB shell version v3.6.2
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core

aprchen commented Jan 31, 2018

I have some situation here, save can take effect, but the modification and deletion are not effective,
image
It turns out to be the same.
image
When I use the following method, the modification succeeds
image

MongoDB extension version => 1.3.4
php version =>7.1.11
MongoDB shell version v3.6.2
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment